1.在$HOME下建立.netrc
2.chmod 0600 $HOME/.netrc
3.向.netrc中添加记录,格式如下:
machine 130.34.1.5 login biansj passWord biansj
...
4.执行exec 130.34.1.5 "ps -ef",将在屏幕上出现远程执行结果
5.写脚本吧:)
我编写的程序如下:
#!/bin/sh
#filename:the test of the telnet a host.
if (rlogin gd_sde >/dev/null 2>1& );then
if(`ps -efgrep accountawk '{if($8!~/grep/) print $9}'grep account`)
then
echo "The account process is exist."
else
echo "Warnning:The account process is not exist."
fi
else
echo "The network to gd_sde is not connected.">2&
fi
exit 0
但发现结果不正确。
用 ssh 连过去也可以, 比如说下面要同时在一台机器上查看多台机器的的httpd服务,如下:
#!/bin/bash
for hostname in 172.168.3.1 172.16.3.2 ........
do
echo $hostname
ssh username@$hostname "ps -efgrep httpd "
done
(出处:http://www.sheup.com)