当前位置: 技术问答>linux和unix
脚本循环错误
来源: 互联网 发布时间:2016-08-07
本文导语: 我想从hostlist里面读取ip,然后去这个IP的机器查询VNC的进程,我的脚本while循环只执行一次,很是郁闷,多谢了。 [user@locathost ~]$ cat bin/vncsession #!/bin/sh if [ -f ~/vncsession ]; then rm -f ~/vncsession fi hostlist=...
我想从hostlist里面读取ip,然后去这个IP的机器查询VNC的进程,我的脚本while循环只执行一次,很是郁闷,多谢了。
[user@locathost ~]$ cat bin/vncsession
#!/bin/sh
if [ -f ~/vncsession ]; then
rm -f ~/vncsession
fi
hostlist=~/bin/hostlist.txt
if [ ! -f $hostlist ]; then
echo "the file $hostlist does not exist! exit now!"
exit 0
fi
while read IP
do
HOST=`rsh -l yluo $IP hostname`
rsh -l yluo $IP ps -ef | grep Xvnc | sed "s/-desktop.*/$HOST/g" | grep -v grep >> ~/vncsession
done
[user@locathost ~]$ cat bin/vncsession
#!/bin/sh
if [ -f ~/vncsession ]; then
rm -f ~/vncsession
fi
hostlist=~/bin/hostlist.txt
if [ ! -f $hostlist ]; then
echo "the file $hostlist does not exist! exit now!"
exit 0
fi
while read IP
do
HOST=`rsh -l yluo $IP hostname`
rsh -l yluo $IP ps -ef | grep Xvnc | sed "s/-desktop.*/$HOST/g" | grep -v grep >> ~/vncsession
done