Link to home
Start Free TrialLog in
Avatar of sunhux
sunhux

asked on

Shell script to rotate & delete/housekeep away highest version logs

I have the following logs in /opt/avscan that's being created by a Shell script's redirection ie >  command)

update.log  (being created daily)

Would like to add extra lines of Shell script into the current script such that prior to running
the command that do > redirect, add the following task:
  if file exists, rm -f update9.log.gz
  if file exists, mv update8.log.gz update9.log.gz
  if file exists, mv update7.log.gz update8.log.gz
  if file exists, mv update6.log.gz update7.log.gz
  if file exists, mv update5.log.gz update6.log.gz
  if file exists, mv update4.log.gz update5.log.gz
  if file exists, mv update3.log.gz update4.log.gz
  if file exists, mv update2.log.gz update3.log.gz
  if file exists, mv update1.log.gz update2.log.gz
  if file exists, mv update.log update1.log
  gzip -9 update1.log
  ...  the rest of the existing Shell script codes ...
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
SOLUTION
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 Tintin
Tintin

Agree with Mike that you should use logrotate.
Avatar of sunhux

ASKER

Thanks chaps;  I still prefer Shell scripts because I'm not at liberty to install
any packages in our tenants' (Solaris) VMs.


WoolMilkPorc,
Is that limited to 9 versions or we can rotate to more versions where needed?
We can make the number of versions variable, if you wish.
ASKER CERTIFIED SOLUTION
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