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
Unix OS

Avatar of undefined
Last Comment
Tintin

8/22/2022 - Mon
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

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
Tintin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy