Method to automatically delete archived log files under Linux

  • 2020-05-14 05:51:47
  • OfStack

1. Log deletion strategy

Automatically delete archived logs and backup files 7 days ago.

2. Schedule

0 0 * * * nohup sh /db2backup/script/auto_rm_logs.sh &

3. Log deletion script


auto_rm_logs.sh
#!/bin/sh
#-------------------------------------
# rm db2 archive log file and *.tgz files @hury
# create @2016-12-13
# script name:auto_rm_logs.sh
# 1.chmod 744 auto_rm_logs.sh
# 2.crontab -e 
# for test only
# */2 * * * * nohup sh /db2backup/script/auto_rm_logs.sh &
# for official
# 0 0 * * * nohup sh /db2backup/script/auto_rm_logs.sh &
#------------------------------------
#params
archlog_path=/db2backup/archlog
backup_path=/db2backup/backup
find $archlog_path -mtime +7 -name "S*.LOG" |xargs rm -f
find $backup_path -mtime +7 -name "*.tgz" |xargs rm -f


Related articles: