• 1 reply
  • Latest Post - ‏2005-11-15T00:03:58Z by SystemAdmin
232 Posts

Pinned topic problem with expect script

‏2005-11-15T00:00:23Z |
Ok, I hope somebody here can help me, because I'm trying this stuff all evening and can't quit get it to work.
I have an expect script:
set timeout 2
log_user 0
spawn ssh lindex $argv 0 -l lindex argv 1 lindex $argv 3
expect "Password:"
send "lindex $argv 2\r"

set log [open lindex $argv 4] w
expect -re .+ {
puts -nonewline $log $expect_out(buffer)

so, what this does, is execute the command
ssh ip -l login command_to_execute_remote
this then asks for a password, it is given, and the output that is produced on the remote machine is stored locally in a file that is given as a parameter.
Now, the problem with this is, it's something for my final year thesis, but I'm kind of new to expect scripting.
What this has to do is, this script is tried several times in a for loop, executed from C++ code. It will trie with several logins and passwords. So, what i want to do, is, it has to check if the login with the given login and password works, if so, it has to capture in a local file the output of the remote command, else, it may not produce an output file, can somebody help me how to do this? I've been trying at this all evening, and am going kind of nuts over it :)

Thanks in advance.
Updated on 2005-11-15T00:03:58Z at 2005-11-15T00:03:58Z by SystemAdmin
  • SystemAdmin
    232 Posts

    Re: problem with expect script

    btw, some other usefull info might be, when a login and password is tried and it is not correct, the remote system just asks for the password again, so you get:
    Password: (here the first time the password is given, it is incorrect)
    so it just asks for the password again if the login is incorrect... Somebody help please :)