LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   password snchronization script (https://www.linuxquestions.org/questions/linux-newbie-8/password-snchronization-script-568169/)

bhandu 07-10-2007 01:39 PM

password snchronization script
 
I have written a shell script which replaces the password of a user in File2 if that user is also present in File1.Following are the contents of two files

File 1

palanspu:3aLdJ8mtCEXJI,A/SS:24563:/usr/bin/ksh
rahul:7j6Zm/48.6rs,A/1S:24669:/usr/bin/ksh


File 2

rahul:ydMaodGCHIzxU,A/jN:25100:/usr/bin/ksh
anukul:YX6UQQl6OpSaU,A/US:25112:/usr/bin/ksh


The script is as follows

#!/bin/bash

#creates array of passwords from File1
pass1=`cut -d ":" -f2 first`
cnt=0

if [ -s tmp-sec ] ; then
rm tmp-sec
else
touch tmp-sec
fi

for usr1 in `cut -d ":" -f1 first` ; do
sed -e "/^$usr1:/ s/:.*$/:${pass1[$cnt]}/" sec >> tmp-sec
cnt=$(($cnt+1))
done


After executing the shell script the output is taken in the file tmp-sec. But I get the error as follows and also the contents of tmp-sec file is not as expected

$ sh temp.sh
sed: Function /^palanpsu:/ /:.*$/:3aLdJ8mtCEXJI,A/SS cannot be parsed.
$ cat tmp-sec
rahul:
anukul:YX6UQQl6OpSaU,A/US:25112:/usr/bin/ksh
$

I have to synchronize the password only using the shell script and by no other way?
Can anyone help?

custangro 07-10-2007 01:44 PM

Have you tired to use awk instead of sed?

Example:

awk -F: '{print $2}' would give you the field you want...

bhandu 07-10-2007 01:54 PM

plz tell me how can I use awk to synchronize passwords


All times are GMT -5. The time now is 05:51 AM.