Subject:System admin and Unix program.
Please use Ubuntu for any Linux scrip
1.Some log messages are extremely important and should be reviewed by an administrator immediately. What scripts or other automation could you set up to make sure that this happens as quickly as possible?
*Please follow these steps to submit your work: Combine your approach and any scripts into a Word document
The approach to alert the admin can be send him the email as soon as any critical logs appear, this can be performed using the following shell script: # vi /opt/scripts/alert_admin.sh #!/bin/bash #Set the variable which equal to zero prev_count=0 count=$(grep -i "`date --date='yesterday' '+%b %e'`" /var/log/messages | egrep -wi 'warning|error|critical' | wc -l) if [ "$prev_count" -lt "$count" ] ; then # Send a mail to given email id when errors found in log SUBJECT="WARNING: Errors found in log on "`date --date='yesterday' '+%b %e'`"" # This is a temp file, which is created to store the email message. MESSAGE="/tmp/log_file.txt" TO="[email protected]" echo "ATTENTION: Errors are found in /var/log/messages. Please Check with Linux admin." >> $MESSAGE echo "Hostname: `hostname`" >> $MESSAGE echo -e "\n" >> $MESSAGE echo "+------------------------------------------------------------------------------------+" >> $MESSAGE echo "Error messages in the log file as below" >> $MESSAGE echo "+------------------------------------------------------------------------------------+" >> $MESSAGE grep -i "`date --date='yesterday' '+%b %e'`" /var/log/messages | awk '{ $3=""; print}' | egrep -wi 'warning|error|critical' >> $MESSAGE mail -s "$SUBJECT" "$TO" < $MESSAGE rm $MESSAGE fi
Get Answers For Free
Most questions answered within 1 hours.