Link to home
Start Free TrialLog in
Avatar of sunhux
sunhux

asked on

Shell script to housekeep lower version files lpt$vpn.xxx

I have the following files (& new files added daily in cron job) in a folder /opt/avscan
-rwxr-xr-x   1 root     root         60M Jul 12 20:50 /opt/uvscan/lpt$vpn.787
-rwxr-xr-x   1 root     root         60M Jul 10 20:50 /opt/uvscan/lpt$vpn.783
-rwxr-xr-x   1 root     root         60M Jul 13 23:57 /opt/uvscan/lpt$vpn.789
-rwxr-xr-x   1 root     root         60M Jul  9 21:49 /opt/uvscan/lpt$vpn.781
-rwxr-xr-x   1 root     root         60M Jul 14 21:52 /opt/uvscan/lpt$vpn.791
-rwxr-xr-x   1 root     root         60M Jun 30 06:17 /opt/uvscan/lpt$vpn.761
-rwxr-xr-x   1 root     root         60M Jul 11 20:49 /opt/uvscan/lpt$vpn.785

I would like to add into the very same Bash Shell script (I suppose I don't
have to share the existing script) that pulls down lpt$vpn.xxxx (can grow
to  lpt$vpn.1001 & higher) that will delete /housekeep away lower version
files.  In this case, we'll leave behind only lpt*.791

I suppose we can use the ctime or atime as a way of deciding which file(s)
to delete:
find /opt/avscan -ctime ... | sort based on date/timing
& then "rm `sorted lpt* list of files | grep -v `tail -1` "   or something like that


Most appreciate if anyone can provide the precise codes & a tested script
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

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
Avatar of sunhux
sunhux

ASKER

Thanks very much, I'll test it out in 30-32 hours' time :
if there's no further clarifications will close this thread
Avatar of sunhux

ASKER

One query: the script given should work in Bash, Korn or Bourne shells, right?
Bash and ksh - no problem.

With "Bourne Shell", do you mean the (very) traditional old bsh?

If so, you will have to run my first suggestion there this way:

echo rm `ls -t '/opt/uvscan/lpt$vpn.'* | tail +2`

My second version should work as posted.