Wednesday, March 6, 2019

Why Crontab Scripts are not running ?

Sometimes The bash scripts runs good at the Terminal, But doesnt execute while running from cromtab.

I faced same issue with multiple commands chained in a crontab,

Solution: Issue behind the command is, while executing crontab everu command should have have the complete path.

You can find the command path as follows:
for example xargs

  • Execute "which xargs" which will give the complete path as /usr/bin/xargs
So I formated my cronjob as follows:

  • Before Path : 44 * * * * echo $(service MyService status | xargs -n 1 lsof -p | wc -l) 
  • After Path : 44 * * * * echo $(/sbin/service MyService status | /usr/bin/xargs -n 1 /usr/bin/lsof -p | /usr/bin/wc -l) 

Keep Exploring.......

No comments: