The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can't create users in /home sdspawankumar SUN Solaris 4 08-21-2008 11:13 AM
How to create users on HP UX???? mascotlee UNIX Desktop for Dummies Questions & Answers 8 07-21-2008 02:02 AM
Application Servers Installation and Users srikanths UNIX for Advanced & Expert Users 2 04-10-2008 12:56 AM
interactive shell script to create users 10.4 tlarkin OS X (Apple) 3 03-27-2008 03:35 PM
create users from template rijeshpp Shell Programming and Scripting 0 10-31-2007 10:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-22-2005
dnidiffer dnidiffer is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 4
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 (permalink)  
Old 09-25-2005
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
  
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 637
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0