1

I have a problem with my cron job.

This is my script for creating mongodb backup:

#!/bin/sh
echo "Running scheduleSpider.sh at \`date\`" >> /tmp/scheduleSpider.sh.log
DIR=`date +\%m\%d\%y`
DEST=/dbbackups/$DIR
mkdir $DEST
mongodump -h localhost:27017 -d xxx -u xxx -p xxxx -o $DEST

This is crontab -u root -e table content:

* * * * * /aamycrons/dbbackup.sh

If I run in terminal:

 sh /aamycrons/dbbackup.sh

This works great its make my DB backup but cron doesn't do that, what em I doing wrong?

3
  • 1
    If you need to run sh /aamycrons/dbbackup.sh as opposed to /aamycrons/dbbackup.sh then you didn't make the script executable. Change permissions like with chmod 755
    – Neil Lunn
    Jun 1, 2017 at 0:28
  • Hi @NeilLunn yes I did on script chmod +x, but now i just changed my crontab command to ' * * * * * /bin/sh /aamycrons/dbbackup.sh' adding /bin/sh and it works! thank you.
    – Nezir
    Jun 1, 2017 at 0:32
  • 1
    @NeilLunn: chmod +x is a bit simpler than chmod 755, and it respects your current umask. zire: if you do chmod +x /aamycrons/dbbackup.sh, then you shouldn't need the /bin/sh in your crontab. Jun 1, 2017 at 0:42

1 Answer 1

0

The solution in my case was to add /bin/sh in crontab. So final crontab -u root -e table content was:

* * * * * /bin/sh /aamycrons/dbbackup.sh

And it's working now!

1
  • 1
    I think you mean crontab, not "crontable". Jun 1, 2017 at 0:46

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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