Expect interactive create account password

Source: Internet
Author: User

#!/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.