- 论坛徽章:
- 0
|
程序目的是备份博科san switch 的配置信息,程序内容如下:
1 #!/usr/bin/perl -w
2 use Expect;
3 $switch_ip = "192.168.17.15";
4 #$Date = `date`;
5
6 $get_log = Expect->spawn( "ssh $switch_ip -l admin") or die "Couldn't spawn ssh,$!";
7 $get_log->log_stdout(1);
8 #$get_log->debug(2);
9
10 if ($get_log->expect(10, -re=>qr /Are .* \(yes\/no\)\?/i) ){
11 $get_log->send("yes\r");
12 }
13
14 elsif ($get_log->expect( 10, -re=>qr/admin\@.* password:/i)) {
15 $get_log->send("1qaz!QAZ\r" );
16 $get_log->send("configupload -scp 192.168.18.201,root,/bakdat/wzs/switch15.txt\r");
17 if ($get_log->expect(2,"Password:")) {
18 $get_log->send("HA5-5tgb\r");
19 }
20
21 }
22
23 #$get_log->send("exit \r");
15行之前执行没有问题,但是执行完16行号后,程序直接退出,为执行17行后面的代码。
执行结果:
HA5-BF01#[/bakdat/wzs/perl]perl san1.pl
admin@192.168.17.15's password:
configupload -scp 192.168.18.201,root,/bakdat/wzs/switch15.txt
-----------------------------------------------------------------
configupload -scp 192.168.18.201,root,/bakdat/wzs/switch15.txt
HA5-SAN15:admin> configupload -scp 192.168.18.201,root,/bakdat/wzs/switch15.txt
Password: HA5-BF01#[/bakdat/wzs/perl]
|
|