Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Problem with sending password

Posted by shafa.fahad (FahaD), 25 September 2006
Hi,

I have been facing a problem which arrises due to prompt

when I expect the user to type the password during ssh, I get a prompt to which i am responding through the script.

But when I send the password stored in a variable during ssh, I get an additional prompt...

For,

set prompt "(%|#|\\$|%]) $"
send_user "Enter Username@System to be logged in: "
expect_user -re "(.*)\n" {set USRSYS $expect_out(1,string)}
spawn ssh $USRSYS
expect {
        -re "Are you sure you want to" {
               send "yes\r"
               exp_continue
       }
        Password: {
       stty -echo
       expect_user -re "(.*)\n"
       send "$expect_out(1,string)\r"
       stty echo

       exp_continue
          }
        -re $prompt {
send "ps -ef|head\r"
expect -re $prompt
set val $expect_out(buffer)
send "exit\r"
}
}

The output is

spawn ssh ms01.mac.com
Could not create directory '/Users/amohapat/.ssh'.
The authenticity of host 'ms01.mac.com (10.13.20.3' can't be established.
RSA key fingerprint is a0:5b:f7:ec:2e:cc:3d:90:ce:55:68:c8:2d:93:6d:d6.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/Users/amohapat/.ssh/known_hosts).
Password:

Last login: Sun Sep 24 23:11:53 2006 from is02-en2
Sun Microsystems Inc.   SunOS 5.9       Generic May 2002
Could not chdir to home directory /Users/amohapat: No such file or directory
Dumping user to /var/tmp
-bash-3.00$ ps -ef|head      ------> only one prompt
    UID   PID  PPID  C    STIME TTY      TIME CMD
   root     0     0  0   May 31 ?        0:01 sched
   root     1     0  0   May 31 ?        3:21 /etc/init -
   root     2     0  0   May 31 ?        0:00 pageout
   root     3     0  1   May 31 ?       1917:48 fsflush
   root   240     1  0   May 31 ?        0:00 /usr/lib/saf/sac -t 300
 nsmail 23837 23830  0   Sep 22 ?        0:00 mailMoveController ms03.mac.com
   root   112     1  0   May 31 ?        0:47 /usr/local/sbin/sshd
   root    65     1  0   May 31 ?        0:00 /usr/lib/sysevent/syseventd
   root    73     1  0   May 31 ?       23:29 /usr/lib/picl/picld
-bash-3.00$


But for

set prompt "(%|#|\\$|%]) $"
send_user "Enter Username@System to be logged in: "
expect_user -re "(.*)\n" {set USRSYS $expect_out(1,string)}
spawn ssh $USRSYS
expect {
        -re "Are you sure you want to" {
               send "yes\r"
               exp_continue
       }
        Password: {
       send "$paswd\r"  --->paswd is a variable where password is stored
         exp_continue
          }
        -re $prompt {
send "ps -ef|head\r"
expect -re $prompt
set val $expect_out(buffer)
send "exit\r"
}
}

the output is

spawn ssh ms01.mac.com
Could not create directory '/Users/amohapat/.ssh'.
The authenticity of host 'ms01.mac.com (10.13.20.3' can't be established.
RSA key fingerprint is a0:5b:f7:ec:2e:cc:3d:90:ce:55:68:c8:2d:93:6d:d6.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/Users/amohapat/.ssh/known_hosts).
Password:

Last login: Sun Sep 24 23:14:59 2006 from is02-en2
Sun Microsystems Inc.   SunOS 5.9       Generic May 2002
Could not chdir to home directory /Users/amohapat: No such file or directory
Dumping user to /var/tmp
-bash-3.00$ -------> I am getting an extra prompt
-bash-3.00$ ps -ef|head
    UID   PID  PPID  C    STIME TTY      TIME CMD
   root     0     0  0   May 31 ?        0:01 sched
   root     1     0  0   May 31 ?        3:21 /etc/init -
   root     2     0  0   May 31 ?        0:00 pageout
   root     3     0  1   May 31 ?       1917:52 fsflush
   root   240     1  0   May 31 ?        0:00 /usr/lib/saf/sac -t 300
 nsmail 23837 23830  0   Sep 22 ?        0:00 mailMoveController ms03.mac.com
   root   112     1  0   May 31 ?        0:47 /usr/local/sbin/sshd
   root    65     1  0   May 31 ?        0:00 /usr/lib/sysevent/syseventd
   root    73     1  0   May 31 ?       23:29 /usr/lib/picl/picld
-bash-3.00$

Because of the above prompt, I am getting inconsistent output which occurs rarely...

And I also found that Even though there is an extra prompt the program works fine most of the times with proper output..

Please help me out to solve the issue

Thanks in advance
Fahad

Posted by admin (Graham Ellis), 25 September 2006
Does $paswd already have a new line character in it, so that you're sending an extra new line?

Posted by shafa.fahad (FahaD), 25 September 2006
oh! ya.. i just checked and it had an extra line...

Now i have solved the issue using trim function.

Thanks for the help..

Regards,
Fahad



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho