Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How do I get expect.pm to ignore special characters?

by sn1987a (Chaplain)
on Apr 15, 2015 at 15:15 UTC ( #1123513=note: print w/replies, xml ) Need Help??


in reply to How do I get expect.pm to ignore special characters?

Do the passwords have the same special characters on the different machines. Some "special" characters are treated differently inside double quotes. To avoid that use single quotes.

$ssh->send( 'rootpasswordwithspecialcharacters' . "\n" );

The single quotes are used to protect that characters in the root password. The newline is then concatenated to the end, since \n depends on being in double quotes.

Replies are listed 'Best First'.
Re^2: How do I get expect.pm to ignore special characters?
by amagana (Acolyte) on Apr 15, 2015 at 18:59 UTC

    Thank you sn1987a,

    Success!, My script can now send and expect from a file and push that to an array. Thank you so very much again now I just need a little more help on how to get my script to make a list of which password resets failed from each list.

      Well you could return values:

      $ssh->expect(5, '#') or return "ERROR"

      You can also lower the amount of timeout, 60 is ok while you make the initial handshake connection, but you must have a WAN if you need to wait 60 seconds for the other prompt. Any way; and at the end of the subroutine:

      return "OK"; }

      Then in your main loop, you pick that value up:

      for my $server (@servers) { # do your thing with $server $rc = change_password($server); if($rc eq "ERROR"){ die "PANIC for $server"} }

      Modify change_password to return a status, true(1) if it succeeded or false(0) otherwise. Then check the return value in the main loop:

      my @fail_servers; for my $server (@servers) { # do your thing with $server push @failed_servers, $server unless change_password($server); }

        Hello friend sn1987a and all,

        I had been away sick with really bad hay fever and since I live in Oklahoma City its even worse here. But I had wanted to come back to this perl script you had been very helpful with me and tell you that everyone's feedback and suggestions have been regarded with very much gratitude. I need to review what I have and where I want it to go.

        Regards,

        "Pergratum habeo"

        Andreas Magana "The Spaniard"

How do get a list of failed servers?
by amagana (Acolyte) on May 12, 2015 at 18:11 UTC

    Hello sn1987a

    The code worked with my solaris boxes but I am having trouble with my script with my Linux boxes it stops at the screen like this example,

    Starting EXPECT pattern matching... at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0x4ecd240)', 60, 'ARRAY(0x4ecd860) +', 'ARRAY(0x4ecd8c0)') called at ./linux_enc.pl li ne 56 main::change_password('remotelinuxhost\x{a}') called at ./linu +x_enc.pl line 39 I've read & consent to terms in IS user agreem't. amagana@remotelinuxhost's password: Starting EXPECT pattern matching.. +. at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0x4ecd240)', 60, '$') called at ./ +linux_enc.pl line 73 main::change_password('remotelinuxhost\x{a}') called at ./linu +x_enc.pl line 39 Permission denied, please try again. amagana@remotelinuxhost's password:

    After that I went to the target box and cleared out the pam_tally2 and then my perl script worked.

      After that I went to the target box and cleared out the pam_tally2 and then my perl script worked.

      If I understood you correctly and the script is now working, then the account got locked while you where debugging your script or was locked for some other failed log in attempts. Is there something that is not working if you run your script now?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1123513]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2019-04-23 08:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (115 votes). Check out past polls.

    Notices?