Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

Gives me:

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

How can I include the executed command too, to make the log look like this:

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
Why not something like * * * * * bash -c 'set -x; date && ... ' >> cron.log 2>&1? – Zoredache Oct 2 '13 at 22:05
@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

Shamelessly putting together the excellent points of @Zoredache and @Glenn in comments, you can wrap your cron command inside bash -xc like this:

* * * * * bash -xc 'date && ... ' >> cron.log 2>&1
share|improve this answer

Your Answer


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

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