Mirroring a user?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mirroring a user?
# 1  
Old 07-30-2007
Computer 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  
Old 07-31-2007
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"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Root Mirroring

Hello Team, In one of our machine which running in AIX 6.1 we doing the root mirroring. Currently the OS booted from the local disk and we have mirrored that in to the SAN disk. All went well and both are synced but when we making it as a multiboot its throwing the below error. Kindly... (4 Replies)
Discussion started by: gowthamakanthan
4 Replies

2. AIX

Use of mirroring concept....

hi.... Friends... Why using mirroring ? what is the use of mirroring? just any one tell about clearly.... thanks.... (4 Replies)
Discussion started by: Kannan841
4 Replies

3. Solaris

Help with HDD Mirroring

Hi All Please can I have some help/advice. I am fairly new to unix so any help will be useful. I need to perform HDD Mirroring on a Sun Fire V245 Server running Solaris 10 OS. The system is already up and running and has the partitions and slices already. Is it possible to perform the... (6 Replies)
Discussion started by: pluto.flame
6 Replies

4. Solaris

Mirroring

Hi All i wish to mirror the root disk, but i face the below error. root@saturn # metainit d11 1 1 c0t0d0s0 metainit: saturn: c0t0d0s0: is mounted on / kindly assist... (27 Replies)
Discussion started by: SmartAntz
27 Replies

5. Solaris

Mirroring Solaris

Hi, I'm trying to setup mirroring, but i get an error. what have done is. prtvtoc /dev/rdsk/c1t0d0s2 | fmthard -s - /dev/rdsk/c1t1d0s2 Then i created the metadb. metadb -a -f c1t0d0s7 c1t1d0s7 now i wan't to metainit. metainit -f d11 1 1 c1t0d0s0 metainit -f d12 1 1... (4 Replies)
Discussion started by: jld
4 Replies

6. Solaris

disk mirroring

hi every body I'm new to solaris and I need your help in how to configure disk mirroring for 4 hard disks so that two of them will be replica to the other two ...??? Thanxx (7 Replies)
Discussion started by: mm00123
7 Replies

7. Solaris

new - How i can implement Mirroring

Unix is something new for me, I trying learn about it now. I have download the sun virtualbox software and install solaris 10 into it. It is is like wizard with step by step installation guideline. :) NOw how can i implement mirroring(RAID) into the my new SunOS? can anyone give a briefly list... (14 Replies)
Discussion started by: webster5u
14 Replies

8. UNIX for Advanced & Expert Users

Mirroring Hardisk

How make mirror hardisk safe and not have trouble when we chance new hardisk in system live in sun solaris 8 server. (3 Replies)
Discussion started by: athurbayunata
3 Replies

9. SCO

Mirroring

How Can I Do Mirroring In Unix? (0 Replies)
Discussion started by: DIMITRIOSDOUMOS
0 Replies

10. Solaris

Mirroring

I am running Solaris 10 and i need to mirror a 73 gig HD. How do you mirror one in Solaris? (2 Replies)
Discussion started by: dewsdwarfs
2 Replies
Login or Register to Ask a Question