The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
SFTP Transfer Across Multiple Servers Cameron Shell Programming and Scripting 0 05-20-2008 06:08 AM
rsh to change multiple ip in multiple servers? kenshinhimura Shell Programming and Scripting 2 02-18-2008 12:04 AM
script to change passwords for the same user on multiple servers stolz Shell Programming and Scripting 6 12-18-2007 10:08 AM
moving files across multiple servers kymberm UNIX for Advanced & Expert Users 2 10-23-2002 09:04 AM
ftp to multiple servers kristy Shell Programming and Scripting 2 12-03-2001 12:49 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-09-2005
Registered User
 

Join Date: Jun 2005
Posts: 4
User add on multiple servers

I have 85 Unix servers & I need to add single user ID on multiple servers at same time
Can anyone help in this?
I have written one script for single servers.same I need to user for multiple servers



#!/bin/sh

echo Enter user login ID
read loginID

echo Enter Group ID
read GroupID

echo Enter user name & Details
read username

echo Enter Login shell
read shell

share_root=/u/shared
grep $loginID /etc/passwd
if [ $? -ne 1 ]
then
echo 'already in system '
else
echo "Adding user..."
useradd -G $GroupID -c "$username" -m -d /Home/$loginID -s $shell $loginID

echo "Set unix users password..."
passwd $loginID
if
Reply With Quote
Forum Sponsor
  #2  
Old 06-09-2005
Registered User
 

Join Date: Feb 2005
Location: Coimbatore, Tamilnadu, India
Posts: 119
If you have setup for non-interactive login into remote machine with,

1) rsh commands
2) ssh commands
3) expect utility

then you can do it in all machines.

Else exection has to be done in single machines.

hth.
Reply With Quote
  #3  
Old 06-09-2005
Registered User
 

Join Date: Feb 2005
Location: Coimbatore, Tamilnadu, India
Posts: 119
Another posibility is with NFS as, one specific share has to be mounted in all 65 unix machines. With in that you can put user ID, group ID, shell etc.

In the script you have to check whether the user is available or not with id command. If not add them else do nothing. You can cron this script to read from that common NFS file.

hth.
Reply With Quote
  #4  
Old 06-09-2005
Registered User
 

Join Date: Jun 2005
Posts: 4
Thanks for your reply.
Actually I want to add user ID on multiple servers thought one single script. I use putty & ssh so I don’t have problem for login on all servers. The problem is how to supply user password interactively in script.
Reply With Quote
  #5  
Old 06-10-2005
Registered User
 

Join Date: Feb 2005
Location: Coimbatore, Tamilnadu, India
Posts: 119
Yes. If you want to make this requirement with one script then proper setup has to be done as,

script running machine --> all other machines

which will not need password for ssh authentication. If you don't want to do this, then you have to give password for every authentication.

username="test"
group="group"
hostfile=./hostfile.log

while read server; do
ssh $server "useradd -g $group $username"
done < $hostfile

./hostfile.log will contain all remote server name.

hth.
Reply With Quote
  #6  
Old 06-10-2005
Registered User
 

Join Date: May 2005
Posts: 40
I would recommend a directory service for your 85 machines, such as NIS or LDAP.
If you still prefer the pain of managing user accounts on 85 machines individually, then:

hth commented with host-based/key-based ssh authentication. You still suffer from providing password for the user account to be added. In this regard, -p option can be used with useradd command. Remember to use encrypted password with -p option. To get encrypted password, perl function crypt can be used.

I bet you would not say password encryption algorithm varies from machine to machine and it is standard unix cryption.

Hope helpful,
Tom
Reply With Quote
  #7  
Old 06-10-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 629
... on the assumption that you have a homogenous Unix environment, you could always just try appending the user's password line into /etc/shadow on the remote machine ...

Code:
1. encrypt the user's password on the local machine
passwd newuser

2. copy the user's password line from /etc/shadow into a tempfile
grep newuser /etc/shadow > /tmp/file 

3. scp the tempfile over to the remote host
scp /tmp/file remhost:/tmp/file

4. ssh to the remote host and cat the tempfile into /etc/shadow and then remove the tempfile
ssh remhost "cat /tmp/file >> /etc/shadow; rm /tmp/file"
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:51 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0