LinuxQuestions.org
Visit the LQ Articles and Editorials section
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, 12:33 AM   #1
bhandu
LQ Newbie
 
Registered: Mar 2006
Posts: 22

Rep: Reputation: 15
Exclamation error in running the shell 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:/ s/:.*$/:3aLdJ8mtCEXJI,A/SS cannot
be parsed.
$ cat tmp-sec
rahul:
anukul:YX6UQQl6OpSaU,A/US:25112:/usr/bin/ksh
$



Can anyone help?
 
Old 07-10-2007, 01:16 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
I didn't look at your entire script. I did notice this line:
pass1=`cut -d ":" -f2 first`

If you want an array use:
pass1=(`cut -d ":" -f2 first`)

Awk might be a better tool for the job. Remember that the /etc/passwd file also contains system users as well, so you need to examine the value of the uid as well.

Linux distro's will also use the shadow suite, so that the encrypted password won't be in the /etc/passwd file.
 
  


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
running a program from shell script Suinatsa Programming 10 04-14-2005 11:25 AM
running SHell script from java anirudh Programming 2 01-07-2005 07:37 AM
Running shell script install, how? henrikanttonen Linux - Newbie 9 08-06-2004 08:46 PM
Running script as user that does not have shell sschueller Linux - General 1 04-24-2004 03:06 PM
c/c++ running a shell script? thermalpants Programming 3 05-12-2002 11:41 AM


All times are GMT -5. The time now is 11:20 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration