Skip to content
Advertisement

Linux – auto restarting with sleep

Current code of mine is

while true; do ./program; done;

I don’t have access to a linux box right now and only way to do my request will be made on the live server and I don’t want to test and jeopardize something, so I would be happy if I could get some help

Is this the way it should be if I want my program to sleep 2 seconds after each restart?

while true; sleep(2); do ./program; done;

Advertisement

Answer

Almost fine.

  1. sleep is a program, so pass him the arguments as space-separated list.
  2. logical test (i.e. true) should be followed immediately by do
  3. If sleep is before ./program, the latter is sleeped before, not after. You could consider reordering them.

while true; do ./program; sleep 2; done;

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement