Tag: shell

Repeating script execution on Linux

When running a PHP script on a Linux server I needed a way to have it start again after ‘crashing’. For example because of an error. It turns out that this is relatively easy using a while loop in bash.

In the file below the command string can be replaced by one or more commands you want to execute.

Simply create the file and execute a chmod +x to make it executable.

The script will run the command and when it terminates, simply loops and run it again. The date command is there so you can see when the script loops during its execution.

#!/bin/sh

while [ 1 ]
do
    date
    command
done

Leave a Comment