expect与shell的整合

2018-03-07  本文已影响0人  钟离寒竹

格式

#!/bin/bash
 shell 语句
/usr/bin/expect<<-EOF
    expect语句
expect eof
EOF

实例

#!/bin/bash
if [ $# == 3 ];then
    user=$1
    oldpasswd=$2
    newpasswd=$3
    /usr/bin/expect<<-EOF
    spawn su $user
    expect " :"
    send " $oldpasswd\r"
    expect eof
    EOF
fi

注意:

     /usr/bin/expect<<-EOF
        expect语句
      EOF

EOF部分要相互对应,即 EOF 是可变的,前后一致即可。

上一篇下一篇

猜你喜欢

热点阅读