2008-06-25

an expect script for ssh login

关键字: linux expect ssh
#!/usr/bin/expect -f
# This script needs three argument to(s) connect to remote server:
# user = Username of remote UNIX Server
# password = Password of remote UNIX server
# ipaddr = IP Addreess of remote UNIX server, no hostname
# For example:
#  ./sshlogin.exp  192.168.1.11 user password sshargv
set user [lrange $argv 1 1]
set password [lrange $argv 2 2]
set ipaddr [lrange $argv 0 0]
set arg1 [lrange $argv 3 3]
set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh $arg1 $user@$ipaddr
match_max 100000
# Look for passwod prompt
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"
# send blank line (\r) to make sure we get back to gui
send -- "\r"
expect eof
评论
发表评论

您还没有登录,请登录后发表评论

pickerel
搜索本博客
最近加入圈子
存档
最新评论