#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Smile Database alert log file monitoring with


    We have customized monitoring Perl script picks up timing data to monitor alert log from oracle alert log file when it is in the format “Wed May 29 23:55:19 2013”. But whereas for Oracle 10.2.0.5 databases oracle writes time zone information also along with date like “Thu May 30 01:30:43 ADT 2013” in alert log file.

    We are using below script to get the timestamp in yyyymmddhhmmss. But the same script has been failing when alertlog file has date format with timezone.

    sub make_timestamp
    {
    my ($day_name,$month_name,$day,$time_stamp,$year,$timestamp);
    chomp @_[0];
    ($day_name,$month_name,$day,$time_stamp,$year) = split (/ +/,@_[0]);
    ($hour,$min,$sec) = split(/:/,$time_stamp);
    ## $day = $padded_number{$day} if ($day < 10);
    $timestamp = $year . $month{$month_name} . $day . $hour . $min . $sec;
    return $timestamp;
    }


    Can you please assist me to fix the script?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,947
    Rep Power
    1225
    It appears that you either don't have the strict and warnings pragmas loaded or you have several of the vars declared on the wrong scope.

    @_[0] should be written as $_[0].

    The first one is an array slice and the second is the array element.

    Why are you using chomp in the sub? That should have been done prior to passing the data to the sub.

    Here's a cleaned up version.
    Code:
    sub make_timestamp
    {
        my ($year,$month,$day,$hour,$min,$sec) = (split(/[:\s]+/, $_[0]))[-1,1..5];
        return $year . $month{$month} . $day . $hour . $min . $sec;
    }
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,947
    Rep Power
    1225
    If you want to make sure each number after the year has 2 digits, then use sprintf to format the string. The return statement would then look like:
    Code:
        return sprintf("%d%02d%02d%02d%02d%02d",
                                                $year,
                                                $month{$month},
                                                $day,
                                                $hour,
                                                $min,
                                                $sec
        );
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0
    Thank you so much for the information. Its worked. you made my day.

IMN logo majestic logo threadwatch logo seochat tools logo