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