Kron PAM Log Rotation and Deleting Old Logs
Log rotation is the mechanism that archives an active log file (e.g., catalina.01-01-2020.out) and initializes a fresh one (e.g., catalina.out) for continued logging. Without periodic cleanup, these archived log files accumulate over time and may gradually consume significant disk space.
To remove outdated log files, use the bash script below. For continuous maintenance, it is recommended to schedule this script as a cron job, ensuring automated log cleanup at regular intervals.
#!/bin/bash #Time threshold to delete files (days). The files older than this threshold will be deleted. threshold=90; find /pam/logs/ -type f -mtime +$threshold -exec rm {} ; find /pam/mobile/log/ -type f -mtime +$threshold -exec rm {} ; find /pam/nssoapp/log/ -type f -mtime +$threshold -exec rm {} ; find /pam/sql/log/ -type f -mtime +$threshold -exec rm {} ; find /pam/sftp/log/ -type f -mtime +$threshold -exec rm {} ; find /var/log/messages* -type f -mtime +$threshold -exec rm {} ;