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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
mirroring in lan between 2 pc hossein SCO 3 03-31-2008 04:13 PM
mirroring ssa to san itik AIX 1 03-25-2008 12:55 PM
Mirroring DIMITRIOSDOUMOS SCO 0 08-12-2006 07:16 AM
Mirroring dewsdwarfs SUN Solaris 2 06-27-2006 04:50 PM
Mirroring drives on Red Hat BG_JrAdmin UNIX for Dummies Questions & Answers 1 02-06-2006 10:23 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-30-2007
syndex syndex is offline
Registered User
  
 

Join Date: Jun 2007
Location: Pennsylvania
Posts: 46
Talking Mirroring a user?

I'm looking for a way to mirror one user to another.

For example:

If I have the user ABC and I want to mirror his:

-Primary group
-Any other groups ABC belongs to
-UID
-Home directory

And create an exact copy over to another server to a user called XYZ. I already have SSH keys set up, don't worry about that, and I have the bulk of the code already .. but..

I'm having trouble writing the bit where it's like:

If

- the user already exists, just use usermod to change XYZ attributes with all of ABC's info.

else

- the user doesn't exist, use useradd to create the account XYZ with all of ABC's info.


Here is the bit of code for the usermod:

ssh -q $id@$servera "sudo usermod -d /home/${user1} -g $primgroup -G $grouplist -u $zaquid $user1"
ssh -q $id@$servera "echo "${user}:examplepass" | sudo chpasswd"

How do I write a statement that will execute that whole block of code, or different block of code. Should I put usermod command and the useradd command as a function and just do something like

if x
then usermod
else
useradd

But how do I determine if the user already has an account?
  #2 (permalink)  
Old 07-31-2007
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,323
Putting usermod and useradd as functions looks more well arranged to me, and to determine whether the user has an account, execute "grep $user-name /etc/passwd";
for example, if I run this from my box :

Code:
grep "^${USERNAME}:" /etc/passwd

would return :
Quote:
sysgate:x:500:500:My Real Name:/home/sysgate:/bin/bash
, having in mind that ${USERNAME} is preset within my "env"
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 01:18 PM.


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