Shell Script to Delete old log files and Send mail
In post I am sharing sample shell script to delete old log file from a location and send mail
Script:
#!/bin/bash# Directory path where log files are storedlog_directory="/u01/oracle/app/diag/test"# Maximum age of log files (in days)max_age=10# Email configurationemail_recipient="support@funoracleapps.com"email_subject="Deleted Log Files Report from TesT"# Delete old log files and collect the deleted file names one by onedeleted_files=$(find "$log_directory" -type f -name "*.log" -mtime +"$max_age" -exec rm {} \; -print)# Generate email bodyif [ -n "$deleted_files" ]; thenemail_body="Deleted log files:$'\n'$deleted_files"elseemail_body="No log files were deleted."fi# Send email to recipientecho "$email_body" | mail -s "$email_subject" "$email_recipient"
Post a Comment
Post a Comment