
script说明
我们单位的物业经常发布断电维护通知,每次断电都需要将所有服务器关掉。这个脚本可以让你做这件事变的简单
#!/usr/bin/perl -w use strict; use Net::SSH::Expect; open (AF, "host_List") or dIE "don't open host_List: $!\n"; my @List; foreach (<AF>) { chomp; @List=split(/\s/); SHUTDOWN("$List[0]","$List[1]","$List[2]","$List[3]"); }; close AF; sub SHUTDOWN { my $host=shift; my $user=shift; my $password=shift; my $wait=shift; my $ssh=Net::SSH::Expect->new ( host=>$host, password=>$password, user=>$user, raw_pty=>1, ); $ssh->deBUG(0); $ssh->run_ssh() or dIE "SSH process Couldn't start: $!"; sleep 3; if ($ssh->waitfor('\(yes\/no\)\?', 2)) { $ssh->send("yes\n"); }; $ssh->waitfor('password', 5); $ssh->send("$password"); $ssh->waitfor("$wait", 2); #$ssh->exec("stty raw -echo"); my $cmd=$ssh->exec("init 0"); # print "$cmd\n\n"; print "$host: --------------------------------------------------\n"; $ssh->close(); }
host_List.txt 格式如下:ip地址 用户名 密码 主机名-----------------------------10.13.55.11 root 1234 gaia10.13.55.10 root aaa- rdfs10.13.55.30 root bbb- dns10.13.55.12 root 1234 dns10.13.55.17 root 1234 dotproject10.13.55.19 root cccc ftp总结
以上是内存溢出为你收集整理的perl ssh 自动登陆多台服务器并执行关机动作全部内容,希望文章能够帮你解决perl ssh 自动登陆多台服务器并执行关机动作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)