关闭

关于expect使用ssh的问题

标签: sshdatebash
633人阅读 评论(0) 收藏 举报

 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" }
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3658238次
    • 积分:59905
    • 等级:
    • 排名:第40名
    • 原创:1549篇
    • 转载:1252篇
    • 译文:0篇
    • 评论:459条
    最新评论