新人虚心求教
昨日,在bash区的各位大师帮忙下完成了个脚本。但在使用过程中发现一个很奇怪的问题,手动执行该脚本的时候一切正常,但只要加入到crontab中就会获取出错误的信息,因此小弟非常迷惑。脚本功能是使用telnet远程获取目标服务器上50001端口的xml信息,并将信息中的内容进行匹配,如果信息中匹配不到"lock status=null"字符串的时候,将会把当前获取到的xml信息l以邮件的方式发送出去。#!/bin/bash
/usr/bin/telnet 192.168.0.7 50001 > /tmp/info.txt
grep -oP '((lock status|user online|login|player count|memory used|free|total)="(*)")' /tmp/info.txt > /tmp/mail.txt
if grep -q 'lock status="null"' /tmp/mail.txt;
then
echo "server is ok" > /tmp/server_ok.txt;
else
mail -s "server is down" admin@test.com < /tmp/mail.txt1、手动执行脚本时的信息lock status="null"
user online="4"
login="0"
player count="6"
memory used="48329760"
free="57097184"
total="105426944"2、crontab执行后发现出现错误信息Trying 192.168.0.7...
Connected to 192.168.0.7.
Escape character is '^]'. crontab的语句怎么写的? 回复 1# 2hcliori
目测是环境变量问题,crontab中不会引入当前用户的环境变量,可以试试在脚本第二行加入:.$HOME/.bash_profile http://bbs.chinaunix.net/viewthread.php?tid=674903#pid4559830
页:
[1]