两个用expect实现自动交互实例

1.

#!/bin/bash

password="iiecas123"

dest_dir="/vds/conf"

for i in `cat $1`

do

  /usr/bin/expect << EOF

    spawn scp ubase.dat $i:/vds/conf/ubase.dat

    set timeout 60

    expect {

      expect "(yes/no)?" { send "yes\r\n" }

      expect "password:" { send "$password\r\n" }

      expect eof

       }

  EOF

done

2.

#!/bin/bash
echo OK
/usr/bin/expect << EOF
spawn ssh root@192.168.0.105
    expect "password:"
    set timeout 300
    send "123456\r"
    expect "]#"
    send "exit\r"
expect eof
EOF

posted @ 2014-12-14 22:25  调皮的猫  阅读(276)  评论(0编辑  收藏  举报