Sunday, September 23, 2018

Crontab Job Is Not Executed As Expected

Symptom

   We have a crontab job as below,  it does not run as expected. The /var/log/cron shows  the cron daemon has invoke it. But no log output.  Manual run is fine but not in crontab job

30 22 * * 1 /almjira_shared/monitor_scripts/lusi/atlassianlabs-lusi-aa6116a95ea3/lusi.sh /u01/app/atlassian/admin/jira/caches/indexes > /almjira_shared/monitor_scripts/lusi/atlassianlabs-lusi-aa6116a95ea3/`hostname -s`-$(date +%F_%R)-output.txt &

Solution:

   The crontab daemon can't recognize  %  in the command line.  We need to escapte % to make it work.  So the correct format is :

30 22 * * 1 /almjira_shared/monitor_scripts/lusi/atlassianlabs-lusi-aa6116a95ea3/lusi.sh /u01/app/atlassian/admin/jira/caches/indexes > /almjira_shared/monitor_scripts/lusi/atlassianlabs-lusi-aa6116a95ea3/`hostname -s`-$(date +\%F_\%R)-output.txt &

No comments:

Post a Comment