3

I have a script that creates a cron job to take a backup of a local MongoDB. When I execute crontab -l command, I see following:

* */1 * * * cd /home/user/shell-scripts && sh mongo-backup.sh

I previously configured the same cronjob to run every minute but then I edited it. I have restarted my machine after editing the job.

What am I doing wrong?

Thanks

MrVaykadji
  • 5,875
  • 2
  • 32
  • 55

1 Answers1

10

use 0 at place of first * like :

0 */1 * * * cd /home/user/shell-scripts && sh mongo-backup.sh

if you use * it means it will execute every minute.

pl_rock
  • 11,297
  • I am trying your solution. – Darshan Puranik Sep 15 '15 at 05:42
  • Thanks for your speedy answer. Now the job is not running every minute. That's a partial success. – Darshan Puranik Sep 15 '15 at 05:55
  • FYI, Backup scripts executes every hour on dot like 6 then 7 and so on with the solution you suggested. It doesnt execute hour after you create cron job. For example if you create cronjob at 5:27 then first execution will be at 6:00, second execution will be at 7:00 and so on. – Darshan Puranik Sep 15 '15 at 07:08
  • yes , if you want to run every hour on 27 minute then you have to do like : 27 */1 * * * cd /home/user/shell-scripts && sh mongo-backup.sh – pl_rock Sep 15 '15 at 07:37
  • @DarshanPuranik - take a look at some crontab examples and tutorial to better understand it, for example http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/ (but Google knows much more and there is always man crontab, although it's rather elaborate and long); also, you can just have /home/user/shell-scripts/mongo-backup.sh instead of cd /home/user/shell-scripts && sh mongo-backup.sh – Marek Bettman Sep 15 '15 at 07:54