Expect script not expecting the password prompt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect script not expecting the password prompt
# 1  
Old 09-24-2016
Expect script not expecting the password prompt

I have a script that does an SSH into a remote node. It should expect the prompt and send the password.

Code:
    #!/usr/bin/expect
    
    
    set user [lindex $argv 0];
    set pass [lindex $argv 1];
    
    spawn ssh $user@E-Internal
    
    expect {
        -re "RSA key fingerprint" {send "yes\r"}
        timeout {puts "\nHost is known"}
    }
    
    expect {
        -re "(P|p)assword: " {send "$pass\r"}
         timeout {puts "Timeout error. Is device down or unreachable?? Password correct?";exit}
    }
    interact

When I run the script :

Code:
    [ruser@vm1 ~]$ /home/rsguser/scripts/git-si-repo/scripts/tunnels/itte-build-node.sh root root123
    spawn ssh root@E-Internal
    
    Host is known
    Timeout error. Is device down or unreachable?? Password correct?

Is there something I am missing ?

If I try to directly SSH, it works like :

Code:
[ruser@vm1 ~]$ ssh root@E-Internal
    root@147.128.64.212's password: 
    Last login: Sun Sep 25 00:25:31 2016 from 142.133.134.161
    [root@ecnshlx3122 ~]#

# 2  
Old 09-26-2016
Have you considered using SSH keys to automate the login? This would be better than trying to work around ssh with expect.

Additionally, your script is vulnerable to people reading it as your password will be visible.

The ssh design is to be secure, so you would be better to exploit that rather than to circumvent it.



Kind regards,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect script to suspend expecting for a time period.

I have a simple Expect script to power a system on and off in an endless loop looking for an ERROR message at which point the script should exit. But I need to skip the first 60 seconds after each power on or off and not exit if there are ERROR messages during that time. I thought I could use... (0 Replies)
Discussion started by: David_Gilhooly
0 Replies

2. Shell Programming and Scripting

How to add password prompt between script ?

Hi Team, I need password prompt between this script .i want to need put password manually. Instead of adding password in script . Script pause till input password and resume again. #!/usr/bin/expect set ip spawn telnet $ip expect "login:" send "USR\r" expect "*assword*"... (3 Replies)
Discussion started by: Ganesh Mankar
3 Replies

3. Homework & Coursework Questions

Shell Script Password Prompt

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to write a shell script that prompts the user for the password which is "lux" once the correct password... (4 Replies)
Discussion started by: Emin_Em
4 Replies

4. Shell Programming and Scripting

Expect doesn't recognize a password prompt

Hi. Here is beginning of my script #!/usr/local/bin/expect -- set timeout 15 spawn /usr/local/account.sh -n modify expect "Password:" {send "mypassword\r"} But due to some terminal control sequences (or something else, dunno exactly) my password prompt is looking like this: and expect... (3 Replies)
Discussion started by: urello
3 Replies

5. Shell Programming and Scripting

Expect Script square bracket dollar prompt

Hi Thanks for this amazing forum first, I've been searching answers in it for problems that I've encountered at work. The only problem I haven't been able to find a fix for, is a ever waiting for prompt problem in Expect when encounter a $ prompt. I usually set the timeout to -1 cause the... (2 Replies)
Discussion started by: Ikaro0
2 Replies

6. Shell Programming and Scripting

enter password at prompt during a script?

I'm using rsync with the "-e ssh" option so of course it asks for a password using a prompt. Is there a way to tell a script to expect a prompt, wait for it, and give a password when it arrives? There is a way to give rsync a password as part of its options using a file, but it only works with... (2 Replies)
Discussion started by: davidstvz
2 Replies

7. OS X (Apple)

Bash script prompt for sudo password?

I'm making a script that will be a double clickable .command file and I need it to prompt for the users admin password. So far I have: if ]; then sudo -p "Please enter your admin password: " date 2>/dev/null 1>&2 if ; then echo "You entered an invalid password... (2 Replies)
Discussion started by: PatGmac
2 Replies

8. Shell Programming and Scripting

sudo, use in script without prompt for password

I need to create an automated script where I have to use sudo to switch to multiple user so the script stops and prompts for password, Is there a way I can provide the password in same command only? Remember that, I cannot disable the password settings of sudo as I dont have rights. (4 Replies)
Discussion started by: gauravgrover50
4 Replies

9. Shell Programming and Scripting

Expect Script....encrypt password and use

Could someone please help me...I have an expect script. There's a need for a log in during the script and a password is required...right now the password is just a variable in the expect script...what would be the best way to put that in an encrypted flat file and have the expect script pull the... (2 Replies)
Discussion started by: cubs0729
2 Replies

10. UNIX for Dummies Questions & Answers

sudo in OS X shell script without password prompt??

I've written a shell script to alter a particular preference file on OS X (10.3.9), which works fine (tested by running the script from the terminal sat in front of the box). Problem is, I now have to run this script remotely across a number of machines via remote desktop, so where I've used the... (1 Reply)
Discussion started by: Brad_GNET
1 Replies
Login or Register to Ask a Question