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
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/kshcd /logsfind . -type f -mtime +7 | while read filedo archdir=/Archive/`dirname $file` mkdir -p $archdir 2>/dev/null mv $file $archdirdone
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
Open in new window