Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: adding wtmp script into logwatch

by sundialsvc4 (Monsignor)
on Nov 30, 2011 at 04:20 UTC ( #940769=note: print w/ replies, xml ) Need Help??


in reply to adding wtmp script into logwatch

You may certainly assume, here at least, that “your knowledge of Perl scripting is very low” will never be interpreted as “dumb.”   Enjoy...

Meanwhile ... “one-liners” are funky at times, but it works much better to put the thing into a .pl file.   Because otherwise (as is the case here...) you run smack-dab into the preferences and the peculiarities of whatever shell you happen to be using, with regards to quote-marks and so forth.   With the possible exception of Windows’ so-called “PowerShell,” Windows’s interpretation of what is a decent shell is virtually non-existent.   ahem.   Build a wtmp script that invokes the Perl code by referencing the Perl code in a file.


Comment on Re: adding wtmp script into logwatch
Re^2: adding wtmp script into logwatch
by hedkandi (Initiate) on Nov 30, 2011 at 09:14 UTC
    hi sundial I did rename the file to a .pl but it didnt work with the logwatch script. i am using a bash shell on suse linux:
    my-mnag0:~ # cat /etc/issue Welcome to SUSE Linux Enterprise Server 10 SP2 (i586) - Kernel \r (\l) +.

      That's because you can't copy and paste the entire thing as a .pl file and expect Perl to understand. Here's what you need to have as the contents of the .pl file:

      #!/bin/perl @type = ( "Empty", "Run Lvl", "Boot", "New Time", "Old Time", "Init" +, "Login", "Normal", "Term", "Account" ); $recs = ""; while (<>) { $r ecs .= $_; } foreach ( split( /(.{384})/s, $recs ) ) { next if length($_) == 0 +; my ( $type, $pid, $line, $inittab, $user, $host, $t1, $t2, $t3, $t +4, $t5 ) = $_ =~ /(.{4})(.{4})(.{32})(.{4})(.{32})(.{256})(.{4})(.{4})(.{4} +)(. +{4})(.{4})/s; if ( defined $line && $line =~ /\w/ ) { $line =~ s/\ x00+//g; $host =~ s/\x00+//g; $user =~ s/\x00+//g; printf( "%s %-8s %-12s +%10s %-45s \n", scalar( gmtime( unpack( "I4", $t3 ) ) ), $type[ unpack( " I4", $type ) ], $user, $line, $host ); } } printf "\n"

      The next step after saving your .pl file is to make it executable using the chmod command. A chmod u+x,g+x,o+x wtmp.pl will do it. Then you can run the script like so:

      ./wtmp.pl

      The above assumes that wtmp.pl is in your current directory.

        Hi Sinistral Thank you for making the script mean something now! I renamed my file, changed the permission to 755, changed the file extension to .pl and when i did run the script I am still gettting syntax errors:
        syntax error at /usr/share/logwatch/scripts/services/my-report line 3 +, near "+," syntax error at /usr/share/logwatch/scripts/services/my-report line 1 +1, near "+;" Nested quantifiers in regex; marked by <-- HERE in m/(.{4})(.{4})(.{3 +2})(.{4})(.{32})(.{256})(.{4})(.{4})(.{4})(. +{ <-- HERE 4})(.{4})/ at /usr/share/logwatch/scripts/services/my-rep +ort line 14.
        sorry my bad. I removed the plus signs, now the script hangs when i run it...
        Hi Sinistral Sorry, Im asking you alot of questions here. So anyways I corrected the "+" signs and it looks like this now:
        #!/usr/bin/perl @type = ( "Empty", "Run Lvl", "Boot", "New Time", "Old Time", "Init", "Login", "Normal", "Term", "Account" ); $recs = ""; while (<>) { $recs .= $_; } foreach ( split( /(.{384})/s, $recs ) ) { next if length($_) == 0 ; my ( $type, $pid, $line, $inittab, $user, $host, $t1, $t2, $t3, $t +4, $t5 ) = $_ =~ /(.{4})(.{4})(.{32})(.{4})(.{32})(.{256})(.{4})(.{4})(.{4} +)(.{4})(.{4})/s; if ( defined $line && $line =~ /\w/ ) { $line =~ s/\ x00+//g; $host =~ s/\x00+//g; $user =~ s/\x00+//g; printf( "%s %-8s %-12s %10s %-45s \n", scalar( gmtime( unpack( "I4", $t3 ) ) ), $type[ unpack( " I4", $type ) ], $user, $line, $host ); } } printf "\n" < /var/log/wtmp
        I added the wtmp directory so the script would call the logs from wtmp...but I am wrong again because the new error I see is this:
        --------------------- WTMP logs Begin ------------------------ Warning: Use of "log" without parentheses is ambiguous at /usr/share/ +logwatch/scripts/services/my-report line 32. syntax error at /usr/share/logwatch/scripts/services/my-report line 3 +2, near "/var/log" Search pattern not terminated at /usr/share/logwatch/scripts/services +/my-report line 32. ---------------------- WTMP logs End -------------------------
        Thank you again for correcting the script, i'm really really grateful for that!
        Helloooo again Sinistral!! OMG I finally got it to work!!! When I ran logwatch it gave me this error saying something like "logfile not defined" because as you can see I hadn't define a log file to call YET into the script (that's why the script was hanging!) Not very bright u see!! Soooo, anyways what I did was to go to my /etc/logwatch/conf/logfiles directory and added a wtmp.conf file and added this line into it:
        my-mnag0:/etc/logwatch/conf/logfiles # ls -lrt total 4 -rwxrwxr-x 1 root sysadm 61 Dec 1 15:11 wtmp.conf my-mnag0:/etc/logwatch/conf/logfiles # more wtmp.conf #Define log file group for wtmp log Logfile = /var/log/wtmp
        so then i rerun logwatch again and lo and behold!!! out came the wtmp logs!!!!
        Wed Nov 30 14:57:35 2011 Normal my9849 pts/0 191.255 + Wed Nov 30 14:58:11 2011 Normal root pts/1 191.255. + Wed Nov 30 15:04:17 2011 Term pts/0 + Wed Nov 30 15:04:25 2011 Normal my9849 pts/0 191.255. + Wed Nov 30 15:22:33 2011 Term pts/0 + Wed Nov 30 15:23:51 2011 Term pts/1 + Thu Dec 1 06:09:22 2011 Normal my9849 pts/0 191.255. + ---------------------- WTMP logs End -------------------------
        OMG Im soo happy!!! This thing has been going on for 2 weeks and I was about to give up until you came along n responded to my distress call!! Thank you soo very much!!! *big hug and kissess

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://940769]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2014-07-30 15:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (235 votes), past polls