AIX idea needed to check the logs updated date and time


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users AIX idea needed to check the logs updated date and time
# 1  
Old 07-15-2013
AIX idea needed to check the logs updated date and time

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:
Code:
#!/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

Code:
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.

Moderator's Comments:
Mod Comment edit by bakunin: thank you for the opportunity to spend some considerable amount of my life cleaning out all the superfluous FONT-, COLOR- and WHATNOT-tags you used instead of wrapping the simple CODE-tags around your code. Which part of the rules, the warning which pops up when opening a new thread and the other reminders to use CODE-tags was so confusing that you couldn't find out what the tags misleadingly labeled "CODE" are for?

Last edited by bakunin; 07-17-2013 at 01:42 AM..
# 2  
Old 07-15-2013
There is no direct command in date to convert it to epoch timings in HP-UX.
You have to write a longer script which will do that.
# 3  
Old 07-17-2013
"-d" is a non-standard GNU extension of the "date"-utility and won't work in probably any POSIXly-correct environment, including AIX. There is an abundance of threads about how to find out yesterdays date in various formats using POSIX tools, just give it a search.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

2. Shell Programming and Scripting

Script to check response time from nginx logs

Hi, My goal is to monitor the response time from the access logs of nginx server. I am using gawk to print the needed fields - 'response time' and 'name of the service' from nginx logs. Command: gawk '($6 ~ /cloudservice/) {print $10, $6}' access.log Output: 0.645 /nc/cloudservice... (6 Replies)
Discussion started by: nshah11
6 Replies

3. UNIX for Dummies Questions & Answers

I need a Script to read Log string and check date at the same time

I need to check 1 log file, which is logging: 2014-08-18T09:10:39+02:00 user: XXXXX START FEATURE 2014-08-18T09:10:39+02:00 user: XXXXX FINISH FEATURE I first need to check that the START FEATURE starts and finish on the same time/date for the same user, which is different each time START... (2 Replies)
Discussion started by: TheBest43
2 Replies

4. Shell Programming and Scripting

Search for logs traced between specific date and time from log file

HI, I want to search for a logs which are trace between specific date and time from logs file. My logs are generated like this :- Tue Jun 18 05:00:02 EEST 2013 | file_check.sh| Message:script has files to process. Thu Jun 20 05:00:02 EEST 2013 | file_check.sh| Message:script has files to... (5 Replies)
Discussion started by: ketanraut
5 Replies

5. Shell Programming and Scripting

How to find last updated date and time of a folder in Perl?

Hi All, I have a process which after some time continues move a files to some folder(say the name of the folder is logdir) What i am trying to do is as the files are coming to the logdir folder, I want the latest updated time and date of the folder in PERL. (1 Reply)
Discussion started by: parthmittal2007
1 Replies

6. Shell Programming and Scripting

How to check crontab edited date and time?

How to check when was the last time the crontab was updated and also what was the modification done ? (2 Replies)
Discussion started by: mail2sant
2 Replies

7. Linux

search on weblogic logs with date time ranges

Hi All, The developers want me to search and capture the weblogic log, you know this big logs of htmls. They want to me to have ranges on the date and time. Like from "2010-01-20 14:04:46,186" to "2010-01-20 15:00:12,490" I can only do this, cat /usr/local/bea/logs_prod1/debug.log... (1 Reply)
Discussion started by: itik
1 Replies

8. Shell Programming and Scripting

search on weblogic logs with date time ranges 2

Hi All, The developers want me to search and capture the weblogic log, you know this big logs of htmls. They want to me to have ranges on the date and time. Like from "2010-01-20 14:04:46,186" to "2010-01-20 15:00:12,490" I can only do this, cat /usr/local/bea/logs_prod1/debug.log |... (1 Reply)
Discussion started by: itik
1 Replies

9. Shell Programming and Scripting

Check Time/Date on a server

I have two servers which are not in sync. I need to write a script that checks the time on the corresponding server and another script to call the above script on both the servers simulataneously to check if there is a time difference. Can anyone provide me with such scripts as I am new to... (3 Replies)
Discussion started by: ravneet123
3 Replies

10. Shell Programming and Scripting

Help needed - Replacing all date & time occurrences in a file with a string using Sed

Hi, I am new to using Sed. I have a file containg lines like the following: INFORM----Test.pc:168:10/11/05 12:34:26 > some text goes here.. TRACE-----Test.pc:197:10/11/05 12:34:26 > some text goes here.. My requirement is to replace 10/11/05 12:34:26 with a string <RUNDATE> (including <... (4 Replies)
Discussion started by: Hema_M
4 Replies
Login or Register to Ask a Question