原文: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
阅读(573) | 评论(0) | 转发(0) |