script to create users on many servers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to create users on many servers
# 1  
Old 09-22-2005
script to create users on many servers

Hi all, working on script to create a user acct on all our servers.

for i in `cat $host_file`; do
ssh $i /usr/bin/sudo /usr/bin/mkuser id='bpadm' gecos='NetBackup Admin' 2>&1 >> $log
done

error i get is: 3004-692 Error changing "id" to "bpadm" : Value is invalid.

I have tried this in various ways, various quotes, tried on the cmd line on the target server. tried it without id= part.

I am just trying to create the user name and a value for gecos.
Server is AIX 5.X, shell is Korn.

thanks, dave
# 2  
Old 09-25-2005
you might be better off appending an entry into the remote box's /etc/passwd file and then creating the home directory as required ...

a. create /etc/password and /etc/shadow strings for the user into temp files
Code:
vi /tmp/pass
vi /tmp/shad

b. transfer the temp files to remote host
Code:
cd /tmp
for remhost in `< /path/to/hostlist`
do
    tar cvfp - pass shad | ssh $remhost "cd /tmp; tar xvfp -"
done

c. append the strings and create home directory as required. put in the correct homedir path as required. please make sure to use ">>" or you'll clobber your files ...
Code:
for remhost in `< /path/to/hoslist`
do
    ssh $remhost "hostname; cat /tmp/pass >> /etc/passwd; cat /tmp/shad >> /etc/shadow; cd /home; mkdir -m 755 bpadm; chown bpadm bpadm; cd /tmp; rm pass shad"
done

the only catch here is your use of sudo ... you might want to put the commands i listed in item d in a script and then call sudo to run the script on the remote box ... assuming that you can put in the root password

the script ...
Code:
#! /usr/bin/ksh

[ -f /tmp/pass ] && cat /tmp/pass >> /etc/passwd
[ -f /tmp/shad ] && cat /tmp/shad >> /etc/shad
[ ! -d /home/bpadm ] && (cd /home; mkdir -m 755 bpadm; chown bpadm bpadm)
rm /tmp/pass /tmp/shad 2> /dev/null

exit 0

the job ...
Code:
for remhost in `< /path/to/hostlist`
do
    scp -p /tmp/script $remhost:/tmp/script
    ssh $remhost "hostname; sudo /tmp/script"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to read through a file and create new users/assign them to groups in Ubuntu

Hi all. I need a shell script that can, in short, read through a text file line by line and create a new user in Ubuntu, as well as assign that user to a group. The format of the text file is not important but preferably: 'username:group'. I don't have much programming knowledge no matter shell... (3 Replies)
Discussion started by: LewisWeekly
3 Replies

2. Shell Programming and Scripting

Script to delete users in the servers

Hi Team, Hope you are doing good.I am new to scripting.I have a requirement of deleting around 10 users in 100 servers.It is very time consuming by logging into each servers and delete the user.Here I have redhat 6 ,Suse linux 10&11 environment servers. In one set of servers I have... (5 Replies)
Discussion started by: muraliinfy04
5 Replies

3. Shell Programming and Scripting

Script to add new users to a group on multiple servers using SSH

Hi Experts, I am new to scripting. We have around 400 Linux servers in our environment. I want to add a new user to a perticular group on all the servers using SSH. Requirements: 1) Need to take the server names from a text file. 2) Login into each server and check whether perticular... (1 Reply)
Discussion started by: Satya1983
1 Replies

4. Shell Programming and Scripting

Shell Script to filter users and create them again from a back-up server

This is a script to filter the users out of etc/passwd and etc/group. So if you want to migrate of restore a server you can use this script from a backup to restore and make the same users on you had.. Please feedback and comments. #!/bin/bash prompt_list () { # haal uit de argumenten de... (5 Replies)
Discussion started by: dannyvdberg
5 Replies

5. Shell Programming and Scripting

Create users from a text file by script

Hi All, I am new to scripting, i want to create one script in which i can add users from a text file, assign them a default password like 123456. It should be like: Username= $i (it should take users from text file one by one) Password : 123456(default for every user) (1 Reply)
Discussion started by: prad_rocxx
1 Replies

6. Shell Programming and Scripting

Help with script to create users from database query

#!/bin/bash user=`mysql userList -uuserlist -puserlistpassword -s -N -e "SELECT userName FROM users WHERE activated='n'"` for i in $user; do useradd "$i" -m doneThis is what I have done so far. But obviously it still does not work. I'm trying to create users based on information stored in a... (5 Replies)
Discussion started by: bucketuk
5 Replies

7. Shell Programming and Scripting

Wants to create 3 users in 400 servers

I wants to create 3 users and set password for the users in 400 servers. I can run this script without error. If wants to set the password in the same command it is not working. Like that i have to create 3 users #!/usr/bin/ksh for server in `cat /tmp/servers` do echo "servername =... (5 Replies)
Discussion started by: G0kulakrishnan
5 Replies

8. Shell Programming and Scripting

Create new users in DMZ box using script

I remote to many DMZ boxes every day to run batch file that allows me to create users. I create users in 17 DMZ boxes every day which takes a lot of my time. Is there any script that would do this job from my local computer? Thank you for your help! (3 Replies)
Discussion started by: idiazza
3 Replies

9. Shell Programming and Scripting

help to create script for added date to list users

hi my friends im asking for the possibility to creat a script in ubuntu for added date to list users for doing this : - search in debug connected user of all connected users - if a new user is connect for the first time to my server the script record the date of the connection and added it... (1 Reply)
Discussion started by: amzioujda
1 Replies

10. OS X (Apple)

interactive shell script to create users 10.4

Hello everyone, Not sure if this is the right place, but OS X isn't your standard Unix, so I figured here would be best. I am looking at creating a script that will be interactive that admins can run to create users. Now, 10.4 uses netinfo database and netinfo manager to handle it's users. ... (3 Replies)
Discussion started by: tlarkin
3 Replies
Login or Register to Ask a Question