LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-31-2008, 02:02 AM   #1
skswati
LQ Newbie
 
Registered: Feb 2004
Posts: 5

Rep: Reputation: 0
Compare Directory and create user


I need some help about the following scenario

i am doing backup of user home directories to a different remote linux system with rsync which is working well the additional thing i want to do is that
after rsync a script should run which compare both locations and check new folders that created on remote backup system (means new user added) and also create that new user with name of folder into that backup system.

i am weak in scripting kindly help.
 
Old 01-31-2008, 08:31 PM   #2
waelaltaqi
Member
 
Registered: Sep 2005
Location: USA, TN
Distribution: CentOS & Ubuntu for Desktop
Posts: 454

Rep: Reputation: 31
rsync itself has the ability to find differences between two directories and copy the differences.
http://everythinglinux.org/rsync/
copying files and creating users are two different things. You could combine both in one script but you don't need to if you have a rsync script already running.
i'm not a scripting guy either but there should be a way to output /etc/passwd from one system to a file then feed that back into adduser command. The following command will show you current users in the system without any other attributes that exist in /etc/passwd
Code:
cut -d ':' -s -f1 /etc/passwd
there should be a way to feed the ouput of the above command into adduser.

Guys ... need some help here?

Last edited by waelaltaqi; 01-31-2008 at 08:49 PM.
 
Old 01-31-2008, 08:45 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
If you want the same users on the remote and the server, you may run into a problem if the users don't have unique UIDs. NIS is usually used for this. Since the filesystem uses the UID number, you may need to change the UIDs of each user on the server and the client hosts and chown and chgrp of each directory and file that is owned by the user. NIS is usually used for this from the start. You may have a lot of work if this wasn't planned out ahead of time.
 
Old 02-06-2008, 12:43 AM   #4
skswati
LQ Newbie
 
Registered: Feb 2004
Posts: 5

Original Poster
Rep: Reputation: 0
thanx for response what i am intrested to do is that
1. with rsync sync all /var/spool/mail and after sync i want to check which folder is new (means new mail user created ) and create that mail user into backupsystem. here is my script for that
#!/bin/bash
# Author : Shahbaz Khan
# Date : 01-02-2007
# Purpose : Backup Mail Folders and create new mail Users

# set vailable for path
DIRPATH="/usr/testbackup"

# before rsync take contents of Directory
ls -A $DIRPATH > /usr/backupscript/old

# Run rsync to sync directories
rsync -zvae ssh root@192.168.X.X:/var/spool/mail/ /usr/testbackup/

# Again take contents of the Direcotory to another file
ls -A $DIRPATH > /usr/backupscript/new

# Compare two files and take difference to variable
#FILEDIFF=`diff /usr/backupscript/old /usr/backupscript/new | cut -f 2 -d ' '`
diff /usr/backupscript/old /usr/backupscript/new | cut -f 2 -d ' ' > /usr/backupscript/diff
#check variable and create user
#for file in `cat < /usr/backupscript/diff`
for USER in `cat < /usr/backupscript/diff`
do

if [ -e $file ]
then
/usr/sbin/useradd -s /sbin/nologin -g mail $USER
echo "created $USER"
fi
done
#END

but the problme is that after diff output into file it has some raw data like 9925a etc and it creates users with that raw data .kindly give me solution to this or give a better idea.
thanx

Last edited by skswati; 02-06-2008 at 12:52 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
create a new user with a different home directory cccc Debian 6 08-06-2008 06:47 AM
Auto Create user home directory on Samba m2azer Linux - Networking 2 01-15-2007 12:56 PM
can i create a user for only one directory. nephish Linux - Networking 2 12-04-2005 07:49 PM
Unable to create directory as user technician Slackware 4 02-15-2004 02:28 AM
adding a new user doesn't create a home directory abrakadabra Linux - General 6 08-09-2002 09:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration