Home > Blockchain >  Shell Script not executing, added to crontab
Shell Script not executing, added to crontab

Time:04-03

Here is my shell script, myscript.sh located in ~/bin

cd ../environment
. env/bin/activate
python3 office.py

The script office.py updates the database. I've tested and works with no issue. I used this command ./myscript.sh

Here is cronjob */5 * * * * cd ~/bin/myscript.sh added to crontab -e

When i check database, no changes. The cronjob isn't running? How do i solve?

CodePudding user response:

You are not running the script but just trying to change directories, which will fail as myscript.sh is not a directory. You need to first cd ~/bin as you are using relative paths in your script and then run the script. Use this line:

*/5 * * * * cd ~/bin && ./myscript.sh

Also you may wanna check the syslog to check for cronjobs.

grep CRON /var/log/syslog

Have a look at this thread for more information on logging cronjobs.

  • Related