0

iam about to blow up: i cant figure out why my jobs in the crontab -e file of any user are not running. None of them do so the "last cron job is not running" problem is not aplicable. Also i checked this thread and couldn't find any mistakes. I even escaped my percent signs.

Here's my crontab -e file when running under the root user:

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# Minute Stunde TagIMonat Monat TagIWoche Kommando
# m h  dom mon dow   command
50 3 * */2 * /usr/bin/openssl pkcs12 -export -out /home/user/export.pfx -inkey /etc/letsencrypt/live/domain/privkey.pem -in /etc/letsencrypt/live/domain/chain.pem -password pass: blabla > /var/log/cron.log
51 3 * */2 * /usr/bin/sshpass -p xxx scp /home/user/export.pfx root@255.255.255.255:/path/to/file/> /var/log/cron.log
0 0 */5 * * /usr/bin/rsync -avx /var/www/nextcloud/apps /nextcloud/backup/path/nextcloud-apps_`date +"\%Y\%m\%d"`/ > /var/log/cron.log
0 0 */5 * * /usr/bin/rsync -avx /var/www/nextcloud/config/config.php /nextcloud/backup/path/nextcloud-config_`date +"\%Y\%m\%d"`/ > /var/log/cron.log
0 0 * * * /usr/bin/mysqldump --single-transaction -h localhost -u user -pPassword db > /nextcloud/backup/path/nextcloud-sqlbkp_`date + "\%Y\%m\%d"`.sql > /var/log/cron.log

Maybe someone can help me with my problem.

Thanks

Salkei
  • 13
  • 1
  • 2

1 Answers1

2

Oh my :)

At first you should not paste such long and complex oneliners into cron directly. Instead, create bash scripts for all these commands.

i.e. you can replace:

0 0 */5 * * /usr/bin/rsync -avx /var/www/nextcloud/apps /nextcloud/backup/path/nextcloud-apps_`date +"\%Y\%m\%d"`/ > /var/log/cron.log
0 0 */5 * * /usr/bin/rsync -avx /var/www/nextcloud/config/config.php /nextcloud/backup/path/nextcloud-config_`date +"\%Y\%m\%d"`/ > /var/log/cron.log

with

0 0 */5 * * /root/bin/rsync_cronjobs.sh > /var/log/cron.log

and move your commands into bash script, i.e. /root/bin/rsync_cronjobs.sh:

#!/bin/bash

DATE=`date +%Y%m%d`

/usr/bin/rsync -avx /var/www/nextcloud/apps /nextcloud/backup/path/nextcloud-apps_${DATE}/
/usr/bin/rsync -avx /var/www/nextcloud/config/config.php /nextcloud/backup/path/nextcloud-config_${DATE}`/

looks cleaner right?

Also, make sure you understand how often these cronjobs are running. You can examine them using cronwtf. For safety never paste anything private (like passwords) into such tools.

Comar
  • 281
  • 1
  • 6