Operating System - HP-UX
1844088 Members
2829 Online
110227 Solutions
New Discussion

basic script (for you guys anyway!)

 
SOLVED
Go to solution
Nik_1
Advisor

basic script (for you guys anyway!)

Hi,

I have a list of .dbf files in a directory, that I would like to 'gzip' up, depending on their date.

At the moment I run:

for i in `ls -1 |grep _1`
do
gzip $i
done


This will zip any files with _1 in the name.

I would like to keep the last 7 days files, so need to use the find command I guess, with -mtime to search for files greater than 10days (ignoring the . & .. entries, and the one .conf file in the list) and gzip them, then maybe report what it's done to an email address... only if it's had to gzip something... if no work had to be done.. no email is sent.

thanks eveyone..

Nik
btw: I'm still working on it now... but I'm sure someone will have a clever 2 liner that'll do it in half the time!
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: basic script (for you guys anyway!)

Hi Nik:

You are on the right track, keep scripting!

Regards!

...JRF...
David Burgess
Esteemed Contributor
Solution

Re: basic script (for you guys anyway!)

Nik,

This should help you on your way

---------------

#delete .dbf files over 7 days old

find . -name "*.dbf" -mtime +7 -exec rm -f {} \;
test -f *.dbf

#if .dbf files exist gzip them and mail dir listing to a user

if [[ $? = 0 ]]
then
for i in $(ls -1 *.dbf)
do
gzip $i
done
ls -la /directory | mailx -s "files are" username@domain.com
fi

----------------

Regards,

Dave.
David Burgess
Esteemed Contributor

Re: basic script (for you guys anyway!)

Sorry comment is in the wrong place.

--------------------

#delete .dbf files over 7 days old

find . -name "*.dbf" -mtime +7 -exec rm -f {} \;

#if .dbf files exist gzip them and mail dir listing to a user

test -f *.dbf

if [[ $? = 0 ]]
then
for i in $(ls -1 *.dbf)
do
gzip $i
done
ls -la /directory | mailx -s "files are" username@domain.com
fi

---------------

Regards,

Dave.
Nik_1
Advisor

Re: basic script (for you guys anyway!)

Thanks David... have assigned points as appropriate.

James: thanks for the motivational reply! I would assign points, but 20,000(!) I figure you have enough already! :)