Operating System - HP-UX
1825768 Members
2070 Online
109687 Solutions
New Discussion

Re: Automated user additions

 
SOLVED
Go to solution
OldSchool
Honored Contributor

Automated user additions

Can anyone tell me if there is a way to automactically set up users on multiple servers by sending a batch file to the servers that would add them? The batch file would of course be manually ftp'ed and a script perhaps running from the cron looking for the delimited file.

Please let me know.

Thanks
14 REPLIES 14
David DeWitt_2
Frequent Advisor

Re: Automated user additions

Tom,

That should certainly work, but I would use Expect to automate that kind of job. Any reason you wouldn't use Expect?

Also, are you looking for script examples?

-dave
Steven E. Protter
Exalted Contributor

Re: Automated user additions

You will need a list of uers names

Here is a working shell to build on.

temppass=Change1
while read -r username
do
useradd $username
passwd <>
$temppass
$temppass
EOF

done < list


SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
OldSchool
Honored Contributor

Re: Automated user additions

I would need a script to set the user environment variable, home directory, etc.

What is Expect?
David DeWitt_2
Frequent Advisor

Re: Automated user additions

Expect is a tool that allows you to automate otherwise un-automatable sessions. Ie: telnet and ftp can be scripted. You could write your own "add_user" script that would initiate a separate telnet session for each server you specified and add the user(s) you specified. If done well it can be highly portable and would require no set up on the target systems. Could be thousands of target systems... I've done something very similar using Expect to automate ftp.

-dave
David DeWitt_2
Frequent Advisor

Re: Automated user additions

Here is a copy of the Expect based ftp script I mentioned. I use it to "push" updated files to several servers.

At a time savings of a few minutes per server, it really adds up after about 20.

-dave
OldSchool
Honored Contributor

Re: Automated user additions

Dave,

Is Expect a software package, if so where can I review it?

Thanks,

Tom
David DeWitt_2
Frequent Advisor
Solution

Re: Automated user additions

Tom,

Expect is apparently included in most UNIX OSes these days. You should be able to do a "man expect" from your UNIX command prompt. If not, I believe you can view it here:

http://expect.nist.gov/

-dave
OldSchool
Honored Contributor

Re: Automated user additions

It appears that Expect was not written with the HP-UX OS in mind, as it will not compile for me in any way. Comes up with the following error:

checking host system type... Invalid configuration `hppa2.0n-hp-hpux11.00': machine `hppa2.0
n-hp' not recognized
David DeWitt_2
Frequent Advisor

Re: Automated user additions

That's unfortunate. It was pre-installed on all of the systems I recently took over. Perhaps someone else has install experience...

Anyone care to help???
Pete Randall
Outstanding Contributor

Re: Automated user additions

You can download a depot version of expect from the porting center:

http://hpux.cs.utah.edu/hppd/hpux/Tcl/expect-5.42/


Pete

Pete
OldSchool
Honored Contributor

Re: Automated user additions

I'll give it a whirl, my systems are on HP-UX 11.00, and the binary was written for 11.11. We'll see. Thanks for the help
Bill Alger
Occasional Advisor

Re: Automated user additions

Tom, See if this helps any.

Build a list of ip addresses you want users added to in a file called /tmp/iplist.txt
Run the following script on this server. This script will put the list of accounts to be added on each server.
NOTE: on line 3,is a root equivilant account that is on every server. Adduser is the account name and passwd is the actual passwd.

cat /tmp/iplist.txt | while read line | do;
if [ -s /tmp/iplistt.txt ]; then
/ftp -inv $line << EOF
user adduser passwd
pwd
bin
prompt
ls $FILE
get $FILE
quit
EOF
else
continue
done
echo "...ftp: ended"


Build the file (/tmp/account.list) in this format:
Account Name:Gecos Name

Run the ftp script.
Now all that is needed is to run a telnet script to add the users.
I have not had a need for this so this part needs a little work.

On each server you can run the following:

Cat /tmp/account.list | while read line| do
echo $line | IFS=":" read id gecos
useradd $id â c $gecos
done

You can also add entries to automatically age them, (such as â x 60 to age out in 60 days).

What you can do is run the scripts in cron.
On every server, run the useradd script at 22:00 every night.
On the one server pushing the lists run the ftp script at 21:00.
You would have to modify the /tmp/account.list file daily, but it would be a one time thing and would add the users.
If no one needed to be added leave the file e
Bill Alger
Occasional Advisor

Re: Automated user additions

Some of my last entry was corrupted. See attachment for what I tried to post
Emil Velez
Honored Contributor

Re: Automated user additions

is nis or NIS+ not a option or why not ldap these technologies allow multi system userids and passwords only get changed in 1 place.