LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Compare Directory and create user (https://www.linuxquestions.org/questions/linux-newbie-8/compare-directory-and-create-user-617572/)

skswati 01-31-2008 01:02 AM

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.

waelaltaqi 01-31-2008 07:31 PM

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?

jschiwal 01-31-2008 07:45 PM

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.

skswati 02-05-2008 11:43 PM

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


All times are GMT -5. The time now is 04:41 PM.