Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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(); }

In reply to How do I get to ignore special characters? by amagana

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (6)
    As of 2020-04-08 09:04 GMT
    Find Nodes?
      Voting Booth?
      The most amusing oxymoron is:

      Results (43 votes). Check out past polls.