Click to See Complete Forum and Search --> : Shell Scripting issues


Mr_Munkey
03-05-2003, 03:27 PM
Hi all,

I'm pretty new to linux, but I learn fast. I'm running SuSE linux 8.1 (FTP install if you want to know) That's probably not important.

here's the problem. I'm working on a shell script to do an automatic archive of files that are older than a certain date, and set it up with cron. This is kind of how it goes:

make sure user is root

ls -l > /mydirectories.txt

now, when I want to check the ownership of those directoris I'm trying to use awk to accomplish my task. I want it to go through each directory one at a time, so I've set it up in a while loop.

while [ "$COUNT" -le "$NUMDIRS" ]
do

if [ "$DIROWN" != "root" ]
then

blah blah blah

fi

COUNT=`expr $COUNT + 1`;

DIROWN is the problem it is :

DIROWN=`awk 'NR == $COUNT {print $3}' /mydirectories.txt`;


I dont know how to use a variable to get the corresponding line in the text file inside of the loop (starting at 2 because awk tells you how many lines there are on the first line)

the loop is working fine, it's just the if statement checking the ownership of the file.

Thanks in advance for any help


PS> just in case, my email is admin@mrmunkey.no-ip.org

Mr_Munkey
03-05-2003, 04:12 PM
Oh yeah, i'm using the Bash shell

chrism01
03-05-2003, 04:56 PM
If you want to find all files not owned by root, in all dirs, starting from current dir:

find . ! -user root -print 2>/dev/null

Mr_Munkey
03-05-2003, 05:17 PM
Thanks, I was thinking way too hard on that one :)

chrism01
03-05-2003, 07:30 PM
Yeah, took me a few reads to (guess) what you were really after...
Thing is with programming, TMTOWTDI (Perl motto: There's More Than One Way To Do IT) pronounced with 3rd t silent ie tim-towdi
:)