Atualizei alguns dos meus arquivos aqui e criei o cron com sucesso para atualizar diariamente meus detalhes do Mongo DB mais detalhes aqui: link
Eu tenho um problema com o meu Cron no Ubuntu 16.04. Verifiquei que o serviço cron está ativo e em execução, mas os scripts que criam backups do Mongo DB provavelmente não são executados.
Este é o conteúdo do meu arquivo / etc / crontab:
# /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 )
#
e aqui está meu conteúdo do arquivo db_backup.sh:
#!/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
Quando eu corro no terminal: sh /etc/cron.hourly/db_backup.sh
É criar um backup do Mongo DB com o nome da data de diretório em / db_backups / somedate
Por que meu script não está sendo executado a cada 10 minutos e 1 hora?
Como você pode ver, eu coloquei o script na pasta cron.hourly, mas nada aconteceu nem 10 minutos nem 1 hora.
Da seção DEBIAN SPECIFIC
de 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).