- 论坛徽章:
- 0
|
本帖最后由 Shrek618 于 2010-05-31 22:11 编辑
例如,我用CRONTAB 执行两个shell脚本,一个叫test1.sh,另一个叫test2.sh
test1.sh 内容如下:
#!/bin/bash
echo "testtest" >> /root/first.txt
test2.sh 内容:
#!/bin/bash
pidlist=`/bin/ps -ef|/bin/grep xclock|/bin/grep $USER|/bin/grep -v "grep"|/usr/bin/awk '{print $2}'`
#ps -u $USER|grep "java"|grep -v "grep"
if [ "$pidlist" = "" ]
then
#/usr/bin/xclock
echo "no xclock pid alive, new clock started" >> /home/two.txt
/usr/bin/xclock
else
for pid in ${pidlist}
{
kill -9 $pid
#echo "KILL $pid:"
#echo "xclock kill success"
}
fi
Crontab
*/1 * * * * /home/test1.sh
*/1 * * * * /home/test2.sh
为什么简单的test1就可以运行工作正常,而test2.sh 就不行。test2 直接在/home 下运行 ./test2.sh 就没有问题
我知道test2有ps, 又if 条件。是太复杂了,还是有别的运行方法呢。。。请指教。。。多谢
更新:
上面从新测试,添加了所有全路径给脚本里用到的命令,而且ECHO 输出也不用出现在屏幕里,是输出到txt 文件。。。这些都没有问题,现在用crontab...运行脚本。。就是/usr/bin/xclock 启动不了。。。这是什么原因? |
|