欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

linux shell expect 处理 passwd 交互

程序员文章站 2022-07-10 11:18:44
...

实例如下:

#!/usr/bin/expect

set username [lindex $argv 0]
set userpass [lindex $argv 1]

# spawn the htpasswd command process
spawn passwd $username

# Automate the 'New password' Procedure
expect "New password:"
send "$userpass\r"

expect "Retype*"
send "$userpass\r"
expect eof

chmod +x scriptname
./scriptname username password