0

I've got a crontab job set to run minutely as such:

* * * * * /home/username/public_html/domain.tld/production/scripts/cron_runner.sh

My goal is to add some timestamps to output from cron so I can find things more easily with regards to some points of failure within a webapp's internal cron system. Sometimes I get messages and sometimes I don't it appears and I want to just perform a sanity check that I've built this script properly here:

#!/usr/bin/env bash
#
# Script Name: cron_runner.sh    
#

echo "Cron Execution @ `date`: " >>/home/username/public_html/domain.tld/production/var/log/crontab_output.log 2>&1

cd /home/username/public_html/domain.tld/production && /usr/local/bin/php /home/username/public_html/domain.tld/production/cron.php >>/home/username/public_html/domain.tld/production/var/log/crontab_output.log 2>&1

echo "==== END CRON EXEC ====" >>/home/username/public_html/domain.tld/production/var/log/crontab_output.log 2>&1

Any suggestions?

3
  • What do you mean by sometimes I get output and sometimes I don't ? Where are you expecting output that you don't see?
    – user9517
    Apr 24, 2013 at 17:30
  • Well Iain, that's the crux. I do not know what to expect precisely and I want to be sure that I am, at the least, setting this up properly so as to not miss any potential output. In this scenario the cron jobs have their own intervals underneath and this is just a master trigger for that webapp cron system. I discovered that one error that I was expecting to see only occurs roughly every 5 min, so that was one reason I wasn't seeing it.
    – ylluminate
    Apr 24, 2013 at 17:54
  • Based on what you have posted, this cron job should run once every minute. It should always post the "cron execution bit" and it should always post the "end cron exec" bit. The php bit may be empty depending on your environment and the php code being executed. Apr 24, 2013 at 17:59

1 Answer 1

1

You could pipe the script to ts from moreutils, which will prepend the timestamp to each line, like for example:

  (cd /home/username/public_html/domain.tld/production && /usr/local/bin/php /home/username/public_html/domain.tld/production/cron.php) | ts >>/home/username/public_html/domain.tld/production/var/log/crontab_output.log 2>&1

Also, each time crond executes a job, it usually logs it under /var/log/cron (depending on *nix flavour), so I should check that out first if applicable to you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .