- 论坛徽章:
- 0
|
本帖最后由 abcfy2 于 2013-05-19 14:09 编辑
事情是这样的,我直接把我的定期计划任务写入了/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: <ok988@iotdemo>
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 <ok988@iotdemo> /home/ok988/mysql_backup/mysql_backup.sh
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin>
X-Cron-Env: <HOME=/home/ok988>
X-Cron-Env: <LOGNAME=ok988>
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: <ok988@iotdemo>
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 <ok988@iotdemo> /home/ok988/monitor_disk.sh
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin>
X-Cron-Env: <HOME=/home/ok988>
X-Cron-Env: <LOGNAME=ok988>
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。解决方案暂时用的是在家目录之外放置脚本。 |
|