expect

#!/bin/sh

if [ $# != 2 ];then
echo "usage: $0 username password"
exit 1
fi
username=$1
password=$2

/usr/bin/expect <<EOF
send_user "execute:$0\n"
set timeout 60

spawn passwd $username

expect "New password"
send "$password\n"

expect "Retype new password"
send "$password\n"

expect {
timeout {exit 1 }
eof {exit 0}
}
EOF

posted @ 2019-03-27 20:56  DaShuZang  阅读(87)  评论(0)    收藏  举报