in reply to Re^6: expect.pm header
in thread expect.pm header
It worked for my. I have modified you program to work in my environment, but the core is still the same. Note how I made a local copy of the header before doing the substitution so the original is available for the other servers
Progam:#!/usr/bin/env perl use strict; use Expect; my $header_template = "\n\n======== system ========\n"; do_date($_) for qw( vftp vwww2 ); sub do_date { my ($system) = @_; my $header = $header_template; $header =~ s/system/$system/; my $timeout = 10; my $ssh = Expect->new("ssh $system"); $ssh->log_file("$system.log"); $ssh->debug(1); $ssh->print_log_file($header); $ssh->expect( $timeout, [qr/password/] ); if ( $ssh->match() =~ m/password/ ) { $ssh->send("youcantseeme\n"); } $ssh->expect( 60, [qr/\$\s*/] ); $ssh->send("hostname\n"); $ssh->expect( 60, [qr/\$\s*/] ); $ssh->send("date\n"); $ssh->expect( 60, [qr/\$\s*/] ); $ssh->send("exit\n"); $ssh->close(); }
vftp.log:
======== vftp ======== jwk@vftp's password: Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.13.0-48-generic x86_64) Last login: Tue Apr 7 22:48:33 2015 from 10.1.1.134 jwk@vftp:~$ hostname vftp jwk@vftp:~$ date Tue Apr 7 22:53:09 CDT 2015 jwk@vftp:~$
vwww2.log:
======== vwww2 ======== jwk@vwww2's password: Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-48-generic x86_64) Last login: Tue Apr 7 22:48:35 2015 from 10.1.1.134 jwk@vwww2:~$ hostname vwww2 jwk@vwww2:~$ date Tue Apr 7 22:53:10 CDT 2015 jwk@vwww2:~$
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: expect.pm header
by amagana (Acolyte) on Apr 08, 2015 at 15:42 UTC | |
by sn1987a (Curate) on Apr 08, 2015 at 17:04 UTC | |
by amagana (Acolyte) on Apr 08, 2015 at 18:19 UTC | |
by sn1987a (Curate) on Apr 08, 2015 at 18:30 UTC | |
by amagana (Acolyte) on Apr 08, 2015 at 19:21 UTC | |
|