Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using ls -lR in a while loop

Status
Not open for further replies.

1971240z

Technical User
Jul 24, 2002
20
US
I need to write a script that will take a list on login information and grep it to get the users home dir. The does a ls -lR looping through the home dirs. This is what I have written.
#! /bin/ksh

while read line
do
ls -lR `egrep "$line" locked_accounts.txt |awk -F: '{print $6}'` >> listolduser
.out
done < chkoldusers.in 2> listoldusererror.out
exit

The chkoldusers.in is a list of the login names.

The locked_accounts.txt is a copy of the users entery in the /etc/passwd file.

This works and gives all the info that I am looking for, but it also give a ls -lR of the dir I ran the script from.

Can anyone help me fix it?

Regards,
 

if I understand correctly, you want a listing of the contents under every users home directories?
if so, this might work...

#! /bin/ksh

while read line
do
ls -lR /home/&quot;$line&quot;
done < chkoldusers.in 2> listoldusererror.out
exit

 
As I see it I think you are getting the listing of your current directory because `egrep &quot;$line&quot; locked_accounts.txt |awk -F: '{print $6}'` fails i.e. returns ''.
Which could mean $line is not in locked_accounts.txt or the 6th field for $line is empty. You could try doing &quot;echo $line&quot; inside the loop so you can find out the culprit $line.
Since I don't know what your data looks like all this just a guess. I may be wrong.
Cheers,
Pravin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top