Linux
Ubuntu Server Cron 作業未執行
我要炸了:我無法弄清楚為什麼我在任何使用者的 crontab -e 文件中的作業都沒有執行。他們都沒有這樣做,“最後一個 cron 作業沒有執行”問題不適用。我也檢查了這個執行緒,沒有發現任何錯誤。我什至逃脫了我的百分號。
這是我在 root 使用者下執行時的 crontab -e 文件:
# 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
也許有人可以幫助我解決我的問題。
謝謝
天啊 :)
一開始你不應該將這麼長而復雜的單行程式碼直接粘貼到 cron 中。相反,為所有這些命令創建 bash 腳本。
即你可以替換:
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 */5 * * /root/bin/rsync_cronjobs.sh > /var/log/cron.log
並將您的命令移動到 bash 腳本中,即
/root/bin/rsync_cronjobs.sh
:#!/bin/bash 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}`/
看起來更乾淨吧?
此外,請確保您了解這些 cronjobs 的執行頻率。您可以使用cronwtf檢查它們。為安全起見,切勿將任何私人資訊(如密碼)粘貼到此類工具中。