1

I have a problem with my Cron on Ubuntu 16.04. I checked that cron service is up and running but scripts that create Mongo DB backups probably is not run.

This is my /etc/crontab file content:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
*/10 * * * * root   test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.hourly )
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

and here is my db_backup.sh file content:

#!/bin/sh
DIR=`date +%m%d%y`
DEST=/db_backups/$DIR
mkdir $DEST
mongodump -h localhost:27017 -d dbname -u xxxx -p xxx -o $DEST

When I run in terminal: sh /etc/cron.hourly/db_backup.sh

Its create Mongo DB backup with dir date name in /db_backups/somedate

Why my script not running every 10 minutes and 1 hour?
As you can see I put script in cron.hourly folder but nothings happen neither 10 minutes or 1 hour.

2 Answers 2

3

From the DEBIAN SPECIFIC section of man cron:

   As  described  above, the files under these directories have to be pass
   some sanity checks including the following: be executable, be owned  by
   root,  not  be  writable  by  group or other and, if symlinks, point to
   files owned by root. Additionally, the file names must conform  to  the
   filename  requirements  of  run-parts: they must be entirely made up of
   letters, digits and can only  contain  the  special  signs  underscores
   ('_')  and  hyphens  ('-').  Any  file  that  does not conform to these
   requirements will not be executed by run-parts. For example, any  file
   containing  dots  will  be  ignored.  This is done to prevent cron from
   running any of the files that are left by the Debian package management
   system when handling files in /etc/cron.d/ as configuration files (i.e.
   files ending in .dpkg-dist, .dpkg-orig, and .dpkg-new).
3
  • I checked file names are okay, removed even underscore from file name and directory and nothing. Is it possible that this file 'dbbackup.sh' must be without '.sh' dot and extension?
    – Nezir
    May 31, 2017 at 14:24
  • @zire underscores are allowed, periods ("dots") are not May 31, 2017 at 14:30
  • I tried with removed .sh in file but nothing happen again @steeldriver
    – Nezir
    May 31, 2017 at 14:44
0

I did update some of my files here and successfully created cron for updating my Mongo DB daily more details here: https://stackoverflow.com/questions/44296616/cron-job-doesnt-work-ubuntu-16-04/44296690?noredirect=1#comment75599631_44296690

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .