Link to home
Start Free TrialLog in
Avatar of vmduddilla
vmduddilla

asked on

Shell Scripting.

Hi,
I need help in a shell script.
I have a direcotry /logs which has subdirectory(s) in it.
i want to have a script to go in to each subdirectory and search for files which are 7 days old and moved to another location with same directory structure.like /logs/apache01 should go to /Archive/apache01.
The problem here is the subdirectory structure is different for different servers.
please advise.
#!/bin/ksh
find /abc/logs/ -atime +2 -exec compress -fv {} \;
ls > 1.txt
for i in 'cat 1.txt';
do
find /abc/logs/$i  -name *.Z -atime +7 -exec mv {} /abc/logs/Archive/$i \;
---------------------
the problem with this script is it is not creating directory and but first time it has to create
Avatar of Tintin
Tintin

Your specifications and code don't match, so I'm going to have to make a whole bunch of assumptions and basing my code on your description.
#!/bin/ksh
cd /logs
 
find . -type f -mtime +7 | while read file
do
  archdir=/Archive/`dirname $file`
  mkdir -p $archdir 2>/dev/null
  mv $file $archdir
done
 
  

Open in new window

Avatar of vmduddilla

ASKER

Sorry if i misguided you..
1) zip files older than 2 days.
2) move .Z files older than 7 days to another location
3)Directory Structure:
/abc/logs/apache01
/abc/logs/apache02
.
.
so on
i have to move .Z files from apache01,apache02,... files older than 7 days to another location with same directory strucure.
( /abc/logs/Archive/apache01
/abc/logs/Archive/apache02

pls advise
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial