美文网首页
expect与shell的整合

expect与shell的整合

作者: 钟离寒竹 | 来源:发表于2018-03-07 20:36 被阅读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 是可变的,前后一致即可。

相关文章

网友评论

      本文标题:expect与shell的整合

      本文链接:https://www.haomeiwen.com/subject/qausfftx.html