Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a way I can include the command in the output when I'm logging to a file? For example

* * * * * date && /path/to/php /path/to/script.php >> cron.log 2>&1

Would give me

Wed Oct  2 14:56:50 PDT 2013
output from script

How can I add the cronjob that just ran to the log? e.g.

Wed Oct  2 14:56:50 PDT 2013
/path/to/php /path/to/script.php
output from script

I'm looking to add this in the crontab and not in the script.

share|improve this question
2  
Why not something like * * * * * bash -c 'set -x; date && ... ' >> cron.log 2>&1? –  Zoredache Oct 2 '13 at 22:05
2  
@Zoredache, excellent idea, you should provide that as an answer. You can add the -x option to the bash command: bash -xc 'date && ...' –  glenn jackman Oct 3 '13 at 0:41
    
Does someone want points for this? :) –  Steve Robbins Oct 8 '13 at 19:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.