How to automate user account creation

From Wiki-UX.info
Jump to: navigation, search

Abstract

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.

Procedure

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/addusers.sh

4. Check the generated script

# cat /tmp/addusers.sh

5. Execute the script

# /usr/bin/sh /tmp/addusers.sh

Reference

Authors