Hi with the help of Gabriel canepa, i have just edited filename only in his code. The help which i got and he helped is
1) I have around 22 logs and each log should be updated in the last 24 hours from the current timestamp.
2) It should check for ERROR message (not error,Error) in the log and if it founds the ERROR means it should send us an update on that.
He has developed a script brilliantly for my sake and the problem is he developed in linux terminal. I have a problem running in my AIX terminal.
The code is as follows:
#!/bin/bash
mailcontents=mailbody
while read line
do
if [ ! -f $line ]; then
echo "The file $line doesn't exist. Continuing with the next file..." >> $mailcontents
echo "============" >> $mailcontents
continue
else
last_mod_time=$(stat -c '%Y' $line) # this line checks the log's last modification time and converts it to Unix's epoch
last_24_hours=$(date +%s -d "24 hours ago") # this line returns the epoch for the current timestamp minus 24 hours
if [ $last_mod_time -lt $last_24_hours ]; then
echo "Log $line has NOT been updated in the last 24 hours" >> $mailcontents
else
echo "Log $line was updated during the last 24 hours" >> $mailcontents
fi
tail -100 $line > checklog
error=$(grep ERROR checklog | wc -l) # We look for the lines containing the word "ERROR" in the checklog file.
# Then we redirect the output to the wc -l command that will count the number
# of lines where the word ERROR appears.
if [ $error -gt 0 ]; then # If this condition is satisfied, that means the word ERROR appeared at least once in
# the log that's being examined in the current loop.[
echo "ERROR found in log $line" >> $mailcontents
else
echo "No errors found in $line" >> $mailcontents
fi
fi
echo "============" >> $mailcontents
done < mylogs
if [ -s $mailcontents ]; then
mail -s "Log errors and last modification times - $(date +'%A %B %d, %Y')" myemail@gmail.com < $mailcontents
fi
rm $mailcontents checklog # Delete auxiliary files when we're done.
I have a problem in this line below while running in the AIX terminal
last_mod_time=$(stat -c '%Y' $line) # this line checks the log's last modification time and converts it to Unix's epoch
last_24_hours=$(date +%s -d "24 hours ago") # this line returns the epoch for the current timestamp minus 24 hours
The AIX terminal is not accepting "date -d" as well as "stat -c"
Can any1 edit the date conversion from unix epoch to current timestamp in a AIX terminal. I really needed it very urgently as there was a CH raised by me for the JULY 3rd week release in my project. Your help is highly appreciated. Please edit the date conversion steps alone for the above script others works like charm as my friend Gabriel said. Thanks in advance. Needed a good and quick response for running the script in AIX terminal.