15

I have this cron

38 * * * * /bin/bash -l -c 'cd /var/rails/site/releases/20120705144335 && script/rails runner -e qa '\''Play.load_lists'\'''

I have this cron under the a different user so I switch users to deploy

sudo su deploy
crontab -e

and i see my cron then i tail the log under the root user

tail -n300 -f /var/log/syslog

and I see my cron

Jul  5 11:38:01 ip-10-70-75-234 CRON[4971]: (deploy) CMD (/bin/bash -l -c 'cd /var/rails/site/releases/20120705144335 && script/rails runner -e qa '\''Play.load_lists'\''')
Jul  5 11:38:01 ip-10-70-75-234 CRON[4970]: (CRON) info (No MTA installed, discarding output)

But the cron is either not running or there is a permission issue...When i run the task in the console it works great but not in the cron...any idea what i am missing

this is Ubuntu 12.04 LTS

Maybe i can log a more detailed list to somewhere to see the errors

Matt Elhotiby
  • 299
  • 2
  • 4
  • 9
  • 2
    According to your log, the job was run. To check it out you could have it log something, e.g. add a `&& echo "I did it">>/tmp/test.log`. Then, after it was run (according to your syslog), check your `/tmp/test.log` if it was a) created and b) has the words in. – Izzy Jul 05 '12 at 16:29
  • where do i add the && echo "I did it">>/tmp/test.log should it look like this 38 * * * * /bin/bash -l -c 'cd /var/rails/site/releases/20120705144335 && script/rails runner -e qa '\''Play.load_lists'\''' && echo "I did it">>/tmp/test.log – Matt Elhotiby Jul 05 '12 at 16:39
  • 1
    I noticed the 'no MTA installed', meaning you have mail output, but no way of sending it. You maybe can install one, and you'd get your info mail. – Rich Homolka Jul 05 '12 at 17:27
  • I solved the issue...i piped the error to a log file and realized I got an error looking for ruby – Matt Elhotiby Jul 05 '12 at 18:10
  • 1
    @Tamer: how did you pipe the error to a log file? – endolith Nov 29 '12 at 02:29

1 Answers1

22

CRON delivers the applications' output (stdout, stderr) via local mail. Ubuntu apparantly does not have an MTA (Mail Transfer Agent) installed by default these days. CRON prints a notification into the systems logfile whenever a delivery failed:

Jul  5 11:38:01 ip-10-70-75-234 CRON[4970]: (CRON) info (No MTA installed, discarding output)

You can install an MTA, e.g. postfix, for internal (local) use only, e.g.

aptitude install postfix

During the installation you will be asked what default configuration to use. You should select the Local only configuration.

Thereafter you can find the output of the applications ran by CRON using

tail -f /var/mail/<your_username>

Of course you can also write the logging output to a dedicated log file or pipe/redirect the output to a file by using built-in shell functionality...

moooeeeep
  • 331
  • 2
  • 7
  • Very useful in helping to make progress here: https://unix.stackexchange.com/questions/585424/sftp-with-redirection-and-here-doc-has-issues-under-cron. It astounds me that an OS wouldn't log the actual error in the log, rather than putting in an email. – NealWalters May 08 '20 at 21:17