-1

I am struggling to create a cron job since morning. Here is the process I did.

The task I am trying to run management.sh,

#!/bin/bash
cd /var/www/mysite.com/myproject/
source ../venv/bin/activate
python manage.py dbbackup
deactivate
  1. I made this script executable by doing sudo chmod +x /var/www/mysite.com/myproject/management.sh.

  2. Then with crontab -e I added the following line to run every 2 mins.

    */2 * * * * /usr/bin/sh /var/www/mysite.com/myproject/management.sh >> /var/log/cron.log 2>&1


Problem

sudo tail -f /var/log/syslog | grep CRON, this is what I see,

Jul 26 09:52:01 test-svr-loc1 CRON[23583]: (dexter) CMD (/usr/bin/sh /var/www/mysite.com/myproject/management.sh >> /var/log/cron.log 2>&1)
Jul 26 09:52:01 test-svr-loc1 CRON[23582]: (CRON) info (No MTA installed, discarding output)

When I check the cron.log, it is empty.

What is wrong here?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Riden Shark
  • 41
  • 1
  • 8
  • Take a look at `/var/log/cron.log`. Your cron tries to tell you that your job is generating errors and cron tries to send it by e-mail, which fails because no MTA ([Mail Transfer Agent](https://en.wikipedia.org/wiki/Message_transfer_agent)) is set up. – Cyrus Jul 26 '20 at 10:12
  • Without access to the error message we really can't tell. The "no MTA" part tells you it tried to send you email with an actual error message, but wasn't able to. Try to pare this down into still simpler components. See also https://stackoverflow.com/questions/22743548/cronjob-not-running – tripleee Jul 26 '20 at 10:14
  • 1
    Is your job allowed to write in `/var/log/cron.log`? – Cyrus Jul 26 '20 at 10:14
  • @Cyrus, thanks. I gave permissions to the log folder and now it is logging. I will create a new question about the issue now. It says cron `can't cd to` folders inside the bash script it is executing. – Riden Shark Jul 26 '20 at 10:34

1 Answers1

0

Crontab is executing script. As per @Cyrus's suggestion in the comments, it was a permission issue. Cron was not able to write to my log as I created it with sudo. Changed permission back to me and it is now logging.

Riden Shark
  • 41
  • 1
  • 8