Perl实现远程上传脚本并执行
发布时间:2020-12-16 00:30:42 所属栏目:大数据 来源:网络整理
导读:? 前面懒人之脚本配置snmp服务?文章提到?,提到用perl 写非交互远程登录,上传安装脚本,并执行。呵呵 ?用了一天才完成,最后朋友给加了,循环。下面脚本经过测试没问题,这脚本还的改进,我需要从服务器上下载日志到本地。 1 #!/usr/bin/perl 2 #Author:luy
? 前面懒人之脚本配置snmp服务?文章提到?,提到用perl 写非交互远程登录,上传安装脚本,并执行。呵呵 ?用了一天才完成,最后朋友给加了,循环。下面脚本经过测试没问题,这脚本还的改进,我需要从服务器上下载日志到本地。1 #!/usr/bin/perl 2 #Author:luyafei 3 #Email:chulianwang@qq.com 4 #The script used as upload script,and execution; 5 use strict; 6 use warnings; 7 use Net::SCP::Expect; 8 use Expect; 10 sub yy { 11 my $host= shift; 12 my $pass= shift; 14 my $scpe = Net::SCP::Expect->new(user=>'root',password=>$pass); 15 $scpe->scp('/home/script/gongzuo/touch.sh',"$host:/tmp/"); 16 }; 18 sub all_host{ 19 my $host = shift ; 20 my $pass = shift ; 22 $ENV{TERM} = "vt100"; 23 my $exp = Expect->new; 24 $exp = Expect->spawn("ssh -l root $host"); 25 $exp->log_file("output.log","w"); 26 $exp->expect(2,[ 27 qr/password:/i,28 sub { 29 my $selt = shift ; 30 $selt->send("$passn"); 31 exp_continue; 32 } 33 ],34 [ 35 'connecting (yes/no)?',36 sub { 37 my $new_self = shift ; 38 $new_self->send("yesn"); 39 } 40 ] 42 ); 43 $exp->send("/tmp/touch.shn") if ($exp->expect(undef,"#")); 44 $exp->send("exitn") if ($exp->expect(undef,"#")); 45 $exp->log_file(undef); 46 } 47 my @laird = ('192.168.1.3','192.168.1.4'); 48 for my $i (@laird){ 50 yy($i,"luyafei"); 51 all_host($i,"luyafei"); 53 } 希望大家多提建议,帮我更好的改进。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |