事情是這樣的,我直接把我的定期計劃任務寫入了/etc/crontab(之前直接用普通賬戶crontab -e不起作用)
但是詭異的事情發生了,/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
#SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
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 )
#
#每天4:00執行mysql備份並拷貝
0 4 * * * ok988 /home/ok988/mysql_backup/mysql_backup.sh
#每6小時執行磁碟空間監測,超過預警給管理員發郵件
0 */6 * * * ok988 /home/ok988/monitor_disk.sh
我會收到錯誤的郵件報警,內容如下:
From ok988@iotdemo Tue Apr 30 04:00:01 2013
Return-Path:
X-Original-To: ok988
Delivered-To: ok988@iotdemo
Received: by iotdemo (Postfix, from userid 1000)
id C30592B034F6; Tue, 30 Apr 2013 04:00:01 +0800 (CST)
From: root@iotdemo (Cron Daemon)
To: ok988@iotdemo
Subject: Cron /home/ok988/mysql_backup/mysql_backup.sh
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
Message-Id: <20130429200001 c30592b034f6="" iotdemo="">
Date: Tue, 30 Apr 2013 04:00:01 +0800 (CST)
/bin/sh: 1: /home/ok988/mysql_backup/mysql_backup.sh: not found
From ok988@iotdemo Tue Apr 30 06:00:02 2013
Return-Path:
X-Original-To: ok988
Delivered-To: ok988@iotdemo
Received: by iotdemo (Postfix, from userid 1000)
id 0E0122B034F6; Tue, 30 Apr 2013 06:00:01 +0800 (CST)
From: root@iotdemo (Cron Daemon)
To: ok988@iotdemo
Subject: Cron /home/ok988/monitor_disk.sh
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
Message-Id: <20130429220002 0e0122b034f6="" iotdemo="">
Date: Tue, 30 Apr 2013 06:00:01 +0800 (CST)
/bin/sh: 1: /home/ok988/monitor_disk.sh: not found
當時安裝系統的時候勾選了加密用戶主目錄,導致crontab認不出來/home/ok988裡面的內容了,crontab執行find命令就會發現/home/ok988下的文件都是亂碼,所以提示not found。解決方案暫時用的是在家目錄之外放置腳本。