所以我建立了一個 cron 作業,如下所示:
GNU nano 2.2.6 File: /tmp/crontab.uNoEXy/crontab
# 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)
#
# m h dom mon dow command
*/3 * * * * /home/kyle/runBackup.sh
對於測試,每三分鐘運行一次腳本。是的,檢查var/log/syslog
- 今天沒有 cron 運行。這個 cron 運行的證據是.tar.gz
我的保管箱資料夾中的一個檔案 - 如果您自己運行腳本,就會發生這種情況。只是將其放入 cron 中就不會發生任何事情。
答案1
嘗試使用:
*/3 * * * * /home/kyle/runBackup.sh
CRON 表達式是一個由五個或由空格分隔的六個字段
答案2
我遇到了一個非常類似的問題,並注意到在計劃運行該作業後,郵件被放置在 root 的 /var/spool/mail 中,該作業被放置在 root crontab 中,說 root 用戶沒有有權運行該作業。環顧四周,結果發現是由於目標腳本無法執行。如果你這樣做:
ls -la /home/kyle/
並且 runBackup.sh 顯示 -rw-r--r-- 權限,然後嘗試:
chmod +x /home/kyle/runBackup.sh
這應該使權限 -rwxr-xr-x 並允許作業運行。