LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 07-10-2007, 02:39 PM   #1
bhandu
LQ Newbie
 
Registered: Mar 2006
Posts: 22

Rep: Reputation: 15
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?
 
Old 07-10-2007, 02:44 PM   #2
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,970
Blog Entries: 1

Rep: Reputation: 208Reputation: 208Reputation: 208
Have you tired to use awk instead of sed?

Example:

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

Last edited by custangro; 07-10-2007 at 02:45 PM.
 
Old 07-10-2007, 02:54 PM   #3
bhandu
LQ Newbie
 
Registered: Mar 2006
Posts: 22

Original Poster
Rep: Reputation: 15
plz tell me how can I use awk to synchronize passwords
 
  


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
get password through shell script shashwat.gupta Programming 6 06-14-2006 02:42 AM
Root Password Script? wellington Linux - Software 5 05-30-2006 01:21 AM
password script wincrk Linux - General 4 04-25-2006 11:16 PM
How to tell shell script a password? Etoile Linux - Newbie 5 04-05-2006 10:16 PM
Help password script jamin123 Linux - Security 1 02-07-2006 09:56 PM


All times are GMT -5. The time now is 12:59 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