Skip to content
Advertisement

Running script in crontab–reboot: command not found

I’ve set a script in my root crontab that is supposed to restart my machine with the reboot command.

However, I am getting a reboot: command not found despite the fact that reboot is in the root user’s path.

JavaScript

My script:

JavaScript

root user crontab:

JavaScript

…yes, this is only a temporary workaround while I figure out why the internet keeps dropping.

Advertisement

Answer

cron jobs run with a very basic environment setup; among other things, the default PATH is just /usr/bin:/bin. It does not use the user’s regular shell setup. There are several ways to solve this:

  • Use the full path in the script (i.e. /sbin/reboot).
  • Set PATH in the script before using reboot (i.e. PATH=/usr/bin:/bin:/usr/sbin:/sbin).
  • Set PATH in the crontab before the entry for your script (syntax is the same as in the script).
Advertisement