0

I have created one shell script which create backup of mongo and push on bitbucket account.

When I run shell script manually, it works fine. But cronjob does not run

Crontab -

00 01,13 * * * /home/ubuntu/work_area/mongodumps/mongo_backup.sh

Shell script

DIR=`date +%m-%d-%y`
#DEST=/home/ubuntu/Desktop/nitin/mongodumps/$DIR
DEST="/home/ubuntu/work_area/mongodumps"
echo $DEST
#mkdir -p $DEST
mongodump --host localhost --port 17117 -d "db_c2a" -o "$DEST"


git add .
#git commit -m `date +%m%d%y+ autocommit`
git commit -m "Auto commit"+$DIR
git push -u origin master

I checked cron log, it is here

Jan 28 01:00:01 ip-172-31-26-102 CRON[5506]: (root) CMD (/home/ubuntu/work_area/mongodumps/mongo_backup.sh)
Jan 28 01:00:01 ip-172-31-26-102 CRON[5505]: (CRON) info (No MTA installed, discarding output)
Jan 28 01:17:01 ip-172-31-26-102 CRON[5523]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
codeforester
  • 39,467
  • 16
  • 112
  • 140
user123
  • 5,269
  • 16
  • 73
  • 121
  • Can you run the shell script as it is without issue? – DarthCaniac Jan 28 '17 at 04:01
  • @DarthCaniac, yes it runs without issue and pushes the code on bitbucket – user123 Jan 28 '17 at 04:03
  • 1
    In your script file, can you echo $PATH and $PWD. It is possible that, when running through cron, these are not what you expect them to be (eg. mongodump and git might not be on that path). Pipe the output to an absolute pathame (eg "/tmp/something.txt") to ensure you know where it is. – racraman Jan 28 '17 at 04:32
  • Try to see if you can follow the guidelines here to manage your cron jobs better: http://stackoverflow.com/questions/41755437/managing-log-files-created-by-cron-jobs/41756145#41756145 – codeforester Jan 28 '17 at 07:23
  • @racraman: I Echoed path, $PWD is correct as expected. – user123 Jan 28 '17 at 12:47
  • 1
    @user123, great, it means they're correct and that the job IS running. Next step is capturing what's happening - so stout,stderr. Cron will try to email these outputs to the job owner, but it looks like you don't have email set up - that's the MTA error (MTA = Mail Transfer Agent). See eg http://askubuntu.com/questions/7993/how-can-i-setup-a-mail-transfer-agent if you want to, but for now just add "> /tmp/job.log 2>&1" to the command in crontab to capture all the output. – racraman Jan 28 '17 at 20:57

0 Answers0