关于expect使用ssh的问题

 spawn bash -c "ssh -t root@$argv"
expect "* (yes/no)*"
send "yes/r"
expect -timeout 1
expect "* password:*"
send "123456/r"
expect -timeout 5
send "export DATE=`date +%F-%R`/r"
expect -timeout 1
send "export IP=`ifconfig |grep /"inet addr/"|grep /"10/"|cut -d ':' -f2|cut -d ' ' -f1`/r"
expect -timeout 1
send "tar cvf /root//$IP--/$DATE.tgz /root/workspace/r"
expect -timeout 1
send "scp -r /root/*.tgz serverIP:/root/back/r"
expect "* (yes/no)*"
send "yes/r"
expect -timeout 1
expect "* password:*"
send "123456/r"
expect eof

用个笨方法

spawn  ssh -t root@$argv
expect {
"* (yes/no)*" { send "yes/r" ; set sshkey 1}
"* password:*" { send "123456/r" }
if $sshkey!=1 {
expect "* password:*"
send "123456/r" }
阅读更多
文章标签: ssh date bash
上一篇expect应用一例
下一篇关于expect使用ssh的问题
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭