How to automate user account creation
Jump to: navigation, search

How to automate user account creation



This document describes a procedure to automate user creation on HP-UX using the entries in the /etc/passwd file, awk to create an automatization script and the Opensource expect utility to automate the password creation.


1. Install expect from the HP-UX Port and Archiving Site

2. Create a file called passwd.exp that contains the following expect automation code:

spawn passwd [index $argv 1]
set password [index $argv 2]
expect "*password:"
send "$password\r"
expect "*password:"
send "$password\r"
expect eof

3. Create a temporary passwd file with only the new logins (no system accounts). Save the file on /tmp/passwd.list

4. Use this awk command to create and script that add all the users on the passwd.list file and reset the password to "newpass".

# awk -F":" '{printf "useradd -g %d -u %d -d %s -s %s %s\nmkdir %s\nchown %s:%d %s\n/usr/local/bin/expect /tmp/passwd.exp %s newpass\n", $4, $3, $6, $7, $1, $6, $1, $4, $6, $1}' /tmp/passwd.list > /tmp/

4. Check the generated script

# cat /tmp/

5. Execute the script

# /usr/bin/sh /tmp/



This page was last modified on 20 April 2011, at 14:57. This page has been accessed 1,890 times.