文章

ubuntu自动创建用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
set timeout 10
set login_pass ******
set username [lindex $argv 0]

spawn id $username
expect {
    "uid=" {
        send_user "User \[$username\] already exists\n"
    }
    "no such user" {
        spawn adduser $username
        expect {
            "New password" { send "$login_pass\r";exp_continue }
            "Retype new password" {send "$login_pass\r";exp_continue}
            "	" {send "\r";exp_continue}
            "Is the information correct?" {send "y\r"}
        }
    }
}
interact
本文由作者按照 CC BY 4.0 进行授权