linux怎么停止脚本

来源:百度知道 编辑:UC知道 时间:2024/06/10 11:51:13
#!/bin/sh
#test2
touch /var/log/loe-ha.log
while :
do
N=`netstat -tln|grep 80`
sleep 1
if [ ! -n "$N" ];then
{
/etc/init.d/heartbeat stop

}
fi
done
~

这个是我写的脚本。。在后台运行。。怎么样让他运行完以后自己退出?

帮我修改下。谢谢。

你是想实现,如果80端口在监听,就把heartbeat服务给stop了,然后就退出?如果是的话,那就这样:
#!/bin/sh
#test2
touch /var/log/loe-ha.log
while :
do
N=`netstat -tln|grep 80`
sleep 1
if [ ! -n "$N" ];then
{
/etc/init.d/heartbeat stop
exit 0
}
fi
done

不过你这个脚本写的似乎有毛病,-n是测试字符串是否为空,非空返回true,空返回false