April 20, 2006
Expect SSH
When you need to automate some interactive console action, expect and autoexpect are the tools you need. Here is an example how to generate a ssh login test and run some simple command.
#!/usr/bin/expect --
# TestSSH.exp
set USER guest
set HOST localhost
set LOOP 10
set COMMAND "echo "test">>/tmp/testme
"
while {$LOOP > 0} {
if [fork]!=0 {
eval spawn ssh $USER@$HOST
set pid $spawn_id
expect {
"(yes/no)?" { send "yes
"; exp_continue}
"^Password" { send "guest
"; exp_continue }
"*>*" { send $COMMAND }
}
expect "*>*"
exit
} else {
set LOOP [expr $LOOP-1]
}
}
exit
Posted 4 years, 9 months ago on April 20, 2006
The trackback url for this post is http://www.avengergear.com/blog/bblog/trackback.php/35/
The trackback url for this post is http://www.avengergear.com/blog/bblog/trackback.php/35/
Comments have now been turned off for this post