Category: linux

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

setuid bit not set on sudo

I encountered the following message when attempting to execute a sudo command on a freshly installed system:

[webdevelop@arkos01 ~]$ sudo su -
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set

To fix this, I had to login as root via SSH (by setting the sshd config value PermitRootLogin to yes) and execute the following command:

chmod u+s /usr/bin/sudo

Leave a Comment