http://www.perlmonks.org?node_id=1123511

amagana has asked for the wisdom of the Perl Monks concerning the following question:

The script stops and says su: incorrect password, these are Linux boxes at when it sends the passwords during the expect/send of su - root.

Is it because I will have to escape the special characters when it starts to send the strings with special characters, I did not have to do this with Solaris boxes?

Is there a way to just alway ignore special characters only during the send part of expect?

#!/usr/bin/perl -w use warnings; use strict; use Expect; my $filename = "/var/tmp/expect_script.log"; my $header = "\r\n\r\n======= system =======\r\n"; my $timeout = 60; #This will open a file and push it to array my @servers; #open (my $file, '<', $ARGV[0]) or die $!; open (my $file, '<', "/home/amagana/scripts/lists/list_b2") or die $! +; while(<$file>) { push (@servers, $_); #push each line of the file to array } print "$_\n" for(@servers); #This is an array #my @servers = qw( # # # # #); for my $server (@servers) { # do your thing with $server change_password($server); } use strict; use Expect; sub change_password { my $system = shift; my $ssh = Expect->new('ssh amagana@' . $system); my $timeout = 60; $ssh->debug(22); $ssh->log_file("$filename"); my $my_header = $header; $my_header =~ s/system/$system/; $ssh->print_log_file($my_header); [ qr/password:/], $ssh->expect ( $timeout, [ qr/password:/], [ qr/Are you sure you want to continue connecting \(yes\/n +o\)?/] ); $ssh->send("yes\r"); if ($ssh->match() =~ m/Are you sure you want to continue connect +ing \(yes\/no\)?/ ) { $ssh->send("yes\r"); } elsif ($ssh->match() =~ m/password:/ ) { $ssh->send("mycurrentpassword\n"); #no problem with the special +characters at this line } $ssh->send("su - root\n"); $ssh->expect(60, '$'); $ssh->send("su - root\n"); $ssh->expect(60, 'Password:'); $ssh->send( "rootpasswordwithspecialcharacters\n" ); #but my scr +ipt quits here $ssh->expect(60, '#'); $ssh->send("hostname\n"); $ssh->expect(60, '#'); $ssh->send("uptime\n");ana\n"); $ssh->expect(60, '#');UNIX Password:'); #linux $ssh->send("passwd amagana\n");pecialcharacters\n" ); $ssh->expect(60, 'New UNIX Password:'); #linux#linux $ssh->send( "mynewpasswordwithspecialcharacters\n" ); $ssh->expect(60, 'Retype new UNIX password:'); #linux $ssh->send( "mynewpasswordwithspecialcharacters\n" ); $ssh->expect(60, '#'); $ssh->send("exit\n"); $ssh->expect(60, '$'); $ssh->send("exit\n"); $ssh->close(); }