求助,关于cron、脚本的执行

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
头像
ilu
帖子: 14
注册时间: 2009-08-16 13:22

求助,关于cron、脚本的执行

#1

帖子 ilu » 2009-08-28 20:57

在ubuntu中写脚本时,其中的有些语句要有root权限才能执行,比如:"hddtemp /dev/sda"。那么在以普通用户登陆的时候怎样才能保证脚本顺利执行呢?不可能每次执行都要输入一次密码吧。尤其是一些计划任务,如cron中的命令。
以下是我写的一个小脚本,但是每次无法执行"hddtemp /dev/sda",见输出文件。
脚本(hdtemp):
echo +++++++++++++++++++++++++++++++++++++++++
echo ---------current time--------------------
date
echo ----------hard drive temperature---------
hddtemp /dev/sda
echo +++++++++++++++++++++++++++++++++++++++++

cron:
# m h dom mon dow command
*/5 * * * * /home/yanxu/hdtemp >> /home/yanxu/hdtemplog

输出(hdtemplog):
yanxu@yanxu-laptop:~$ cat hdtemplog
+++++++++++++++++++++++++++++++++++++++++
---------current time--------------------
Fri Aug 28 20:35:01 CST 2009
----------hard drive temperature---------
+++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++
---------current time--------------------
Fri Aug 28 20:40:02 CST 2009
----------hard drive temperature---------
+++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++
---------current time--------------------
Fri Aug 28 20:45:01 CST 2009
----------hard drive temperature---------
+++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++
---------current time--------------------
Fri Aug 28 20:50:01 CST 2009
----------hard drive temperature---------
+++++++++++++++++++++++++++++++++++++++++
回复