cron.hourly job not running

Alexander asked:

OS: Ubuntu 16.04

I’ve looked at a lot of different articles and threads, and I still can’t get my cron.hourly jobs to run automatically. I am trying to run a backup on my PostgreSQL database. In /etc/cron.hourly, I have only one script named pg_backup. Here are the permissions on it:

-rwxr-xr-x   1 root root  1543 Oct 16 19:07 pg_backup

If I run run-parts --test /etc/cron.hourly, the output is as follows:

/etc/cron.hourly//pg_backup

That looks good. If I run the script using run-parts manually, it works as expected and backs up my database. Here’s the command I’m using:

run-parts -v --report /etc/cron.hourly

That’s great, but for whatever reason, it’s not running every hour by itself. I really don’t know what could be wrong. I’ve checked all the logs and haven’t been able to find any error messages.

What am I missing?

UPDATE

I noticed that my /etc/crontab file has the shell specified like so: SHELL=/bin/sh. My script runs in bash. Is it sufficient to have the shebang at the top of my script for it to use bash? #!/bin/bash

UPDATE 2

As suggested by Broco, I put the job in my crontab, and it’s still not working. Here’s what I did:

sudo crontab -e

Then I added the following to the file:

* * * * * root /etc/cron.hourly/pg_backup

I made it run every minute to get quicker feedback on whether or not it’s running, and it seems to be running but isn’t actually performing the backup.

Here’s part of my syslog. I used the command grep CRON /var/log/syslog:

Oct 17 14:02:01 User CRON[63871]: (root) CMD (root /etc/cron.hourly/pg_backup)
Oct 17 14:02:01 User CRON[63870]: (CRON) info (No MTA installed, discarding output)
Oct 17 14:03:01 User CRON[63917]: (root) CMD (root /etc/cron.hourly/pg_backup)
Oct 17 14:03:01 User CRON[63916]: (CRON) info (No MTA installed, discarding output)
Oct 17 14:04:01 User CRON[63966]: (root) CMD (root /etc/cron.hourly/pg_backup)
Oct 17 14:04:01 User CRON[63965]: (CRON) info (No MTA installed, discarding output)
Oct 17 14:05:01 User CRON[64013]: (root) CMD (root /etc/cron.hourly/pg_backup)
Oct 17 14:05:01 User CRON[64012]: (CRON) info (No MTA installed, discarding output)
Oct 17 14:05:01 User CRON[64014]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Oct 17 14:06:01 User CRON[64060]: (root) CMD (root /etc/cron.hourly/pg_backup)
Oct 17 14:06:01 User CRON[64059]: (CRON) info (No MTA installed, discarding output)
Oct 17 14:07:01 User CRON[64106]: (root) CMD (root /etc/cron.hourly/pg_backup)
Oct 17 14:07:01 User CRON[64105]: (CRON) info (No MTA installed, discarding output)

My answer:


Your cron job is running, but the job is having a problem.

You normally should get an email with the output (and errors!) but you do not get email because:

Oct 17 14:02:01 User CRON[63870]: (CRON) info (No MTA installed, discarding output)

You don’t have anything installed on your system that is capable of sending mail. Thus, the output is thrown away.

Consider installing an MTA so that you can have the output emailed to you and then find out what is actually happening.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.