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 +)
1
  • 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, 2017 at 19:36

2 Answers 2

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

0
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.