Perl Expect Module to give passwords for remote sudo commands
Hi All,
I have written a script to run commands on remote servers, it is working fine. But when I am running "sudo commands" on the remote servers, it asks for me password after prompting for ssh password. I am unable to automate this password prompt (which is just after ssh password prompt). This is the function I am using to provide passwords Code:
pass () Code:
[sudo] password for vikas: Code:
ssh -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no 192.168.1.100 "bash rcmds" This is my script output Quote:
Thanks in advance. |
I think perl's expect handles regex in the patterns so you could use a pattern like below to match both of them
Code:
$exp->expect($timeout, |
Quote:
This too not working for me. Same error. :( |
Hi All/Estabroo
I was not able to provide two password entries simultaneously, but I did a work around. I first added ssh-keys and then ran sudo command through ssh , and then supplied password from my pass function. This indeed worked well for me :) BUT, still my question remains the same, how to provide input automatically when there is more than one input is required. For E.g. ssh-keygen -t dsa requires user to press enter key (taking all defaults) 4-5 times. Anyway to automate this through perl-Expect ? |
edit the sudoers file to disable passwords for some commands.
|
Quote:
|
you have a silly customer.
:-) perhaps the admin at the other end is a bit rubbish? I'm glad it isn't my job. can you not convince them this is impractical? |
have you tried using autoexpect
it usually comes with expect. That's usually where I start. |
Quote:
|
All times are GMT -5. The time now is 01:28 PM. |