View the Most Wanted LQ Wiki articles.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 07-10-2007, 12:33 AM   #1
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


File 2


The script is as follows


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

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

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

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
sed: Function /^palanpsu:/ s/:.*$/:3aLdJ8mtCEXJI,A/SS cannot
be parsed.
$ cat tmp-sec

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

Rep: Reputation: 657Reputation: 657Reputation: 657Reputation: 657Reputation: 657Reputation: 657
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.


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 06:20 PM.

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