I am trying to run bash script as a cron job every 15 minutes.
The bash script simple calls a Java program. I made an entry in crontab to run the file every 15 minutes and saved it but it would not do anything ?
crontab -e
*/15 * * * * /home/marshell/graphite_cronjobs/Run_Cron_Read_Send_CapacityData_To_Graphite.sh
Run_Cron_Read_Send_CapacityData_To_Graphite.sh
java Cron_Read_Send_CapacityData_To_Graphite >> Cron_Read_Send_CapacityData_To_Graphite.log
There are two possible issues here. First of all, cron runs jobs in a special shell which does not read your personal $PATH. If
java
is not in/usr/bin
or/bin
, it will not be available to cron. Fromman 5 crontab
:So, use the full path to
java
instead. The next issue is that your bash script calls java on a file with a relative path. It assumes that the script will be launched from the same directory as the java file. Again, this is not the case. So, always use absolute paths for your scripts if you want them to run as expected by cron:Alternatively, you can set the
$PATH
in the crontab itself: