-2

I have a bash script which is calling another python script.

This is not running in cron because of python global variable. Please find below the script. Script is meant to zip logs and move to Amazon s3. When we run the script from terminal it will work. But when ran from cron it will zip contents then s3cmd which is a python script it fails. Can anyone help me with setting python global variable at cron level.

#!/bin/bash
cd /applications/java/tomcat-instance/foundation/logs/
sudo find /applications/java/tomcat-instance/foundation/logs/ -mtime +1 | xargs tar -czvPf tomcat_logs_`date +%Y%m%d`_`date +%H`.tar.gz
/usr/bin/python s3cmd put /applications/java/tomcat-instance/foundation/logs/tomcat_logs_`date +%Y%m%d`_`date +%H`.tar.gz s3://merck-ghh-logs/preview/deliver$
sudo find /applications/java/tomcat-instance/foundation/logs/ -mtime +7 -exec rm {} \;
Ajo Mathew
  • 628
  • 1
  • 5
  • 25

2 Answers2

0

Provide the full path to s3cmd-:

 /usr/bin/python /path/to/s3cmd put ....
suspectus
  • 16,548
  • 8
  • 49
  • 57
  • cron will normally send mail when an error occurs. Can you see any emails from cron? The user emailed to will be the same as the user that setup the cron job. – suspectus Mar 18 '13 at 12:10
  • I set up it as root user `sudo crontab -e`. I had faced same issue when I ran another script which was bash but it needed some other arguments. That time I placed it on top of crontab and it started working. Here its a python script and the script is not running. – Ajo Mathew Mar 18 '13 at 12:17
  • ok. check root email for a cron error or check the cron logs. – suspectus Mar 18 '13 at 12:20
  • Error I am getting is `CRON[3342]: (CRON) info (No MTA installed, discarding output)` – Ajo Mathew Mar 18 '13 at 12:25
  • Check the cron log, look in /var/log. Errors possibly can be found using `grep -i cron /var/log/syslog` – suspectus Mar 18 '13 at 12:30
0

Cron Job is running under root users.

I gave sudo in the command. I observed that some commands won't run when.

  1. Cronjob is running under root.
  2. Sudo is used in it.
Ajo Mathew
  • 628
  • 1
  • 5
  • 25