2

i have a problem with executing terminal simple command in crontab.

Terminal view:

touch  /home/eugene/`date +%d-%m-%y-%s`.txt

Crontab view:

* *     * * *   root    touch  /home/eugene/`date +%d-%m-%y-%s`.txt

If i run this command in terminal, everything works perfect.

Cron log file view (File: /var/log/cron.log):

Aug 30 22:15:01 eugene-desktop CRON[8809]: (root) CMD (   touch  /home/eugene/`date +)
Aug 30 22:16:01 eugene-desktop CRON[8859]: (root) CMD (   touch  /home/eugene/`date +)
Aug 30 22:17:01 eugene-desktop CRON[8896]: (root) CMD (   touch  /home/eugene/`date +)
  • I dont write commands directly in crontab. I write them in a shell script and then execute shell script from crontab. – luv.preet Aug 30 '17 at 19:36

2 Answers2

2

The crontab requires full path of the command. The normal path is not used in crontab.

Try /bin/touch or /usr/bin/touch, instead of just touch

luv.preet
  • 5,787
1

I believe your script should be:

* * * * *   root  /usr/bin/touch  /home/eugene/`date +%d-%m-%y-%s`.txt

The full path to the touch command should be used

George Udosen
  • 36,677