Expect: Difference between revisions
Jump to navigation
Jump to search
(New page: Links. http://floppsie.comp.glam.ac.uk/Glamorgan/gaius/scripting/5.html http://expect.nist.gov/scripts/) |
No edit summary |
||
Line 2: | Line 2: | ||
http://floppsie.comp.glam.ac.uk/Glamorgan/gaius/scripting/5.html | http://floppsie.comp.glam.ac.uk/Glamorgan/gaius/scripting/5.html | ||
http://expect.nist.gov/scripts/ | http://expect.nist.gov/scripts/ | ||
<pre> | |||
Script. | |||
#!/usr/bin/expect -f | |||
# | |||
# expect_ssh.exp | |||
# bjorklun | |||
# | |||
if { $argc < 1 } { | |||
send_user "Usage: ./ssh-login.exp <username> <password> <hostname> <command> \r" | |||
exit | |||
} | |||
# | |||
set username [lrange $argv 0 0] | |||
set password [lrange $argv 1 1] | |||
set hostname [lrange $argv 2 2] | |||
set command [lrange $argv 3 3] | |||
set arguments [lrange $argv 4 9] | |||
set timeout -1 | |||
match_max 1000 | |||
spawn ssh $username@$hostname $command $arguments | |||
expect { | |||
"Are you sure you want to continue connecting (yes/no)? " { | |||
send -- "yes\r" | |||
expect "*?assword:*" { | |||
send -- "$password\r" | |||
send -- "\r" | |||
} | |||
} | |||
"*?assword:*" { | |||
send -- "$password\r" | |||
send -- "\r" | |||
} | |||
"*denied*" { | |||
puts "You are a loser Andreas\r" | |||
} | |||
} | |||
expect eof | |||
</pre> |
Revision as of 15:57, 14 May 2008
Links.
http://floppsie.comp.glam.ac.uk/Glamorgan/gaius/scripting/5.html http://expect.nist.gov/scripts/
Script. #!/usr/bin/expect -f # # expect_ssh.exp # bjorklun # if { $argc < 1 } { send_user "Usage: ./ssh-login.exp <username> <password> <hostname> <command> \r" exit } # set username [lrange $argv 0 0] set password [lrange $argv 1 1] set hostname [lrange $argv 2 2] set command [lrange $argv 3 3] set arguments [lrange $argv 4 9] set timeout -1 match_max 1000 spawn ssh $username@$hostname $command $arguments expect { "Are you sure you want to continue connecting (yes/no)? " { send -- "yes\r" expect "*?assword:*" { send -- "$password\r" send -- "\r" } } "*?assword:*" { send -- "$password\r" send -- "\r" } "*denied*" { puts "You are a loser Andreas\r" } } expect eof