0

I'm writing a crontab where I want a certain script to run every time my machine is rebooted, something like this:

PATH=/root/.nvm/versions/node/v20.16.0/bin
TZ=GMT
@reboot cd /mydirectory && ./myscript.sh > /root/boot-log.txt 2>&1 &

This crontab is run from the root user but the script itself can be used by other users and contains the sudo command, when I restart my machine I check boot-log.txt file and a series of messages like:

./myscript.sh: 1: sudo: not found

Which makes me think for some reason I just can't use sudo on a script started by the crontab, but why is that? Is there a way to fix it so that the script runs correctly?

1 Answers1

0

In the end, I was able to fix the issue by adding /usr/bin to the PATH, which is the path to sudo executable

PATH=/root/.nvm/versions/node/v20.16.0/bin:/usr/bin