您的位置:首页 > 其它

自动登录多台远程主机查看进程是否正常

2008-01-21 11:49 337 查看
原文:http://blog.chinaunix.net/u/12442/showart_391130.html

很多时候管理员需要登录多台主机,检查进程执行是否正常。

以下脚本在HP-UX上顺利实现,估计在其他平台也没问题的,毕竟都是bash嘛,呵呵

1、脚本的实现前提条件是,所有要的远程主机的/.rhosts中包含你目前所处的本机的名字
2、创建主机列表
3、输出重定向到日志文件:当日日期.ping.log
4、同时用tail -f 来查看实时的运行结果

#!/sbin/sh

logfile=/etc/chk/log/`date +%Y%m%d`.run.log
if [ -f "$logfile" ]; then
rm $logfile
fi
touch $logfile

tail -f $logfile &

for i in `cat /etc/chk/hosts.run.lst`
do
(sleep 10;echo "ps -ef | grep run |wc -l";sleep 3;echo exit;) | rlogin $i >/etc/chk/run.tmp
tail -n 3 /etc/chk/run.tmp >> $logfile
done

rm /etc/chk/run.tmp

kill `ps -f -u root | grep "tail -f $logfile" | awk '{print $2}'` >/dev/null

exit
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: