#!/usr/bin/expect
Set user [lindex $argv 0]
Set pass [lindex $argv 1]
Spawn useradd-s/bin/sh-d/home/$user $user
Expect "*#"
Spawn passwd $user
Expect "*password:"
Send "$pass \ r"
Expect "*password:"
Send "$pass \ r"
Spawn Smbpasswd-a $user
Expect "*password:"
Send "$pass \ r"
Expect "*password:"
Send "$pass \ r"
Interact
Comments:
Spawn: followed by shell commands to execute
Expect: only spawn executed command results will be captured expect, because Spawn will start
Process , only the relevant information of this process will be captured, mainly including: standard inputThe following information, EOF and timeout. send and Send_user:send send the information needed in the expect script to spawn startupprocess, and Send_user just echoes the message from the user, similar to the echo in the shell andhas been. Set script parameter, expect is through set < variable name > [lindex $argv <param Index>]
Expect interactive create account password