Operating System - HP-UX
1833875 Members
2940 Online
110063 Solutions
New Discussion

Problems with a script that cycles log files

 
SOLVED
Go to solution
wvsa
Regular Advisor

Problems with a script that cycles log files

Greetings having a problem with a script that is used to cycle log files. We have a directory /wv/dvlp/rms/log. Under the log directories we have several directories for example /wv/dvlp/rms/log/dira, dirb, etc. Under /wv/dvlp/rms/log/dira there maybe a directory and underneath that directory there maybe another directory. With the script I have I can cycle the log files in the /wv/dvlp/rms/log/dira directory but cannot cycle the log files that are in directories below /wv/dvlp/rms/log/dira. Here is the script:
cd $1
for i in `ls -l |grep "^d"| tr -s " " " "|cut -d" " -f9`
do
cd $i
for x in `ls -l -R |grep "^d"| tr -s " " " "|cut -d" " -f9`
do
echo $x
cd $x
for l in `ls`
do
cycle $l 2
done
cd ..
cd $x
echo "In sub dir"
done
cd ..
done

Any help would be greatly appreciated. Please don't limit your responses to fixing my script I'm sure someone out there has a better way of accomplishing this task. Again thankyou for your response.

--Norm Long--
--World Vision--
4 REPLIES 4
Joseph C. Denman
Honored Contributor

Re: Problems with a script that cycles log files

I would use the find command.

cd $1
find ./ -type d | while read line
do
cd $line
whatever you want
done

...jcd...
If I had only read the instructions first??
Joseph C. Denman
Honored Contributor

Re: Problems with a script that cycles log files

Whooops, that wont work.

Howabout something like this:

home=/where/you/want/to/start
find $home -type d | while read line
do
cd $line
#cycle your stuff
done


If I had only read the instructions first??
someone_4
Honored Contributor
Solution

Re: Problems with a script that cycles log files

I have attached a script that clears out log and compresses log files. I have modified it to clear out some other logs as well as system logs. Maybe you can take the basic concept of it and rewrite it a little to help you do what you need.
Hope it helps Richard

Richard
Stefan Schulz
Honored Contributor

Re: Problems with a script that cycles log files

If you just want to "cycle" every file you find in your logs directory, why do you have to cd in every single directory.

What you do is to go down every directory under your starting point. Then you cycle every file you find.

I would think it is easier to just stay where you are and cycle every file from there. Like

cd $1
find . -type f | while read line
do
cycle $line 2 # or what ever you want
done

Hope this helps

Regards Stefan


BTW: Your profile says: "This member has assigned points to 28 of 78 responses to his/her questions." Please assign points as they help others to find the best solution that was provided.
No Mouse found. System halted. Press Mousebutton to continue.