将测试进行到底!

实现批量telnet并执行远程服务器上的shell脚本

上一篇 / 下一篇  2011-03-28 11:28:02 / 个人分类:监控服务器

telnetstart.sh和telnetstop.sh只需要放在一台服务器上就可以(确定这台机器对每台机器都可以telnet进去并可以操作,每台机器的监控用户/密码都相同,否则找主机管理员建立相同的监控用户/密码)。

telnetstart.sh代码:
#telnetstart.sh

user=weblogic
passwd=weblogic
ipaddress[0]="192.168.252.2"
ipaddress[1]="192.168.252.3"

for I in ${ipaddress[@]}
do
{
    {
        sleep 1
        echo  "$user"
        sleep 1
        echo  "$passwd"
        sleep 1
        echo "cd /home/weblogic/nmon"
        sleep 1
        echo  "./nmonstart.sh 1 120 test"
        sleep 1            
    } | telnet "$I"
}
done
exit 0

telnetstop.sh代码与telnetstart.sh相似,就不说啦。

验证成功:
[weblogic@localhost nmon]$ ./telnet.shTrying 192.168.252.2...Connected to 192.168.252.2 (192.168.252.2).Escape character is '^]'.
    localhost.localdomain (Linux release 2.6.9-78.ELsmp #1 SMP Fri Jul 25 00:04:28 EDT 2008) (2)
login: weblogicPassword: Last login: Sat Mar 26 14:06:36 from 192.168.252.2[weblogic@localhost ~]$ cd /home/weblogic/nmon[weblogic@localhost nmon]$ ./nmonstart.sh 1 120 test[weblogic@localhost nmon]$ Connection closed by foreign host.Trying 192.168.252.3...Connected to 192.168.252.3 (192.168.252.3).Escape character is '^]'.CentOS release 4.7 (Final)Kernel 2.6.9-78.ELsmp on an i686login: weblogicPassword: Last login: Sat Mar 26 23:31:02 from 192.168.252.2[weblogic@mytest ~]$ cd /home/weblogic/nmon[weblogic@mytest nmon]$ ./nmonstart.sh 1 120 test[weblogic@mytest nmon]$ Connection closed by foreign host.
验证192.168.252.2[weblogic@localhost nmon]$ ps -ef | grep nmonweblogic  6945     1  0 14:10 ?        00:00:00 ./nmon -F /home/weblogic/nmon/110326/Linux-localhost-201103261410-test.nmon -s 1 -c 120weblogic  6986  6771  0 14:10 pts/1    00:00:00 grep nmon[weblogic@localhost nmon]$ 验证192.168.252.3[root@mytest ~]# ps -ef | grep nmonweblogic  6836     1  0 23:34 ?        00:00:00 ./nmon -F /home/weblogic/nmon/110326/Linux-localhost-201103262334-test.nmon -s 1 -c 120[root@mytest ~]# 

TAG:

不要安于现状=奋斗=永不停息 引用 删除 wangyong3552128   /   2011-03-28 11:37:08
乱码啦
 

评分:0

我来说两句

Open Toolbar