0

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.

janos
  • 808
  • 1
  • 6
  • 22
Steve Robbins
  • 1,932
  • 5
  • 23
  • 26

1 Answers1

0

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
janos
  • 808
  • 1
  • 6
  • 22