0

I'm having problem getting my crontab to work in my ubuntu server 18.04 running as a amazon ec2 instance.

I have the following line in my /etc/crontab file:

*/15 * * * *     root    /bin/bash /home/ubuntu/gzip/over_time_compile_ec2.sh

But it does not seem to work, and when running sudo service cron status i get the following:

Feb 14 22:20:01 ip-172-31-15-110 CRON[15880]: pam_unix(cron:session): session opened for user ubuntu by (uid=0)
Feb 14 22:20:01 ip-172-31-15-110 CRON[15879]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 14 22:20:01 ip-172-31-15-110 CRON[15881]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 14 22:20:01 ip-172-31-15-110 CRON[15882]: (root) CMD (/home/ubuntu/gzip/compile_script.sh)
Feb 14 22:20:01 ip-172-31-15-110 CRON[15883]: (ubuntu) CMD (/home/ubuntu/gzip/compile_script.sh)
Feb 14 22:20:01 ip-172-31-15-110 CRON[15884]: (root) CMD (/bin/bash /home/ubuntu/gzip/over_time_compile_ec2.sh)
Feb 14 22:20:01 ip-172-31-15-110 CRON[15881]: (CRON) info (No MTA installed, discarding output)
Feb 14 22:20:01 ip-172-31-15-110 CRON[15881]: pam_unix(cron:session): session closed for user root
Feb 14 22:20:01 ip-172-31-15-110 CRON[15880]: (CRON) info (No MTA installed, discarding output)
Feb 14 22:20:01 ip-172-31-15-110 CRON[15880]: pam_unix(cron:session): session closed for user ubuntu

I see the line (CRON) info (No MTA installed, discarding output), but it should not make my CRON fail right?

  • It's telling you that the script tried to write something, but that there was nowhere for it to go. What you don't know at this point is whether that was an error message (which might explain why it's presumably not working) or something else. I would recommend you append something like >/tmp/otce.log 2>&1 to the end of your crontab entry and take a look inside that file after the next 15 minute cycle. – roaima Feb 14 at 22:33
3

Having no MTA (like postfix or similar) installed will not make your cron job fail, but it prevents cron from being able to send the owner of the job any output of the job via email.

If your job failed (for any reason), or produced output, you would not get notified about it and that information would be discarded.

If you don't want to install an MTA, use a redirection of the job to a log file:

*/15 * * * * root /bin/bash /home/ubuntu/gzip/over_time_compile_ec2.sh >/tmp/job.out 2>/tmp/job.err

This would put standard output messages in /tmp/job.out and any diagnostic messages that the job generates into /tmp/job.err. You may also redirect both types of messages into the same file with >/tmp/job.out 2>&1.

With >, these files would be emptied and rewritten each time the job runs. With >>, the files would be appended to (but leave 2>&1 as is, if you redirect to the same file; 2>>&1 would not work).

  • Thanks, just to clarify, you are sure there is nothing wrong with the syntax or layout in the crontab file? – emilrn Feb 14 at 22:41
  • 1
    @emilrn The syntax looks correct for the system crontab file in /etc/crontab. In a user's crontab file edited via crontab -e, the 6th field (with the username) should not be there. – Kusalananda Feb 14 at 22:42
  • @emilrn You can also see that the log says that it's actually running the correct command, your script. So the cron side of things work. You just have to capture the output of the actual script to see what's going on. – Kusalananda Feb 14 at 22:47
  • 1
    I often use what I call poor man's logrotate for such cronjobs: */15 * * * * root /bin/bash … 1>/tmp/job-$(date '+\%M').out 2>&1 This will create logfiles with the current minute in their name. Because the job runs every 15 minutes you'll have 4 logfiles (job-00.out, job-15.out, ...) and no housekeeping is needed. If you use $(date '+\%H\%M') instead (hour, minute) you'll have 24*4=96 files for one day and they overwrite themselves after a day in a round-robin fashion. – PerlDuck Feb 15 at 10:32
-1

In my file over_time_compile_ec2.sh there were a path to another script as cron were in the current directory, as it was not.

So i just added the full path over the other script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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