当前位置:Linux教程 - Shell - shell - 登陆到多台主机上去查看相关进程返回结果

shell - 登陆到多台主机上去查看相关进程返回结果

登陆到多台主机上去查看相关进程返回结果
2004-04-23 15:18 pm
来自:Linux文档
现载:Www.8s8s.coM
地址:无名

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 -ef|grep account|awk '{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 -ef|grep httpd "
done