I have a working bash script and I want to run this script every minute with root privileges using crontab. I created my crontab as follows.
>sudo crontab -e
Then the file opened and I entered my cron job as follows.
* * * * * /home/pi/myscript.sh
This works. I see that my script is being run every minute. However, some of the lines of code in my script need to have root privileges to run. So, my script fails as a result even though it is being run every minutes. Then, I did what others suggested online.
* * * * * root /home/pi/myscript.sh
This didn't work at all. Cron failed to execute my script completely after adding root. Then, I tried the following by adding the user pi
* * * * * pi /home/pi/myscript.sh
Again, this didn't work at all. As before Cron failed to run my script. However, when I run the script right on terminal like sudo ./myscript.sh
, it runs successfully with no problems. I understand that when you sudo crontab -e
, it supposed to open cron jobs for root or superuser by default.
My script's permission is anyone can execute, anyone can read and only owner can modify.
My PI is PI2 and running Raspbian (Jessie).
myscript.h
, perhaps we can help?