I am working on a Perl script to run from an AIX Nim server to extract hardware errors from our Linux server using various forms of grep statements -
I have all my hosts in a text file and a command is run from the nim server to each host to pull out data from /var/log/messages and compile it into an email.
I seem to be strruggling with the following line:
in that I am getting thousands of multipath io messages and only want to print it in my report if it occurs once.
e.g.
Is there a way I can do this through using egrep/grep? I have been using '-m' option but it doesn't seem to be helping.
i just want my script to produce a report from each server's messages file for those hardware faults but not filling up my mailbox.
...fully 93% of this is shell code -- literally running in a shell, since perl creates whole, actual shells every time you use a set of backticks. In a large enough program you could be wasting dozens of shell instances.
I, too, used to write perl code like this. Eventually I threw away the perl, since it did nothing but hold together 19 different shells.
Anyway. About your logic, you can also bundle those handfuls of egrep -v's into a single
I don't think the -m option makes much sense when using -v.
...but grep doesn't have if-then logic. It's not a language. It can't make decisions later about things that happen now.
awk is a language, which can do absolutely all of that:
All the red backslashes are junk you need to do this in perl, because it will turn awk's $0/$1/etc into its own variables without it. They're not necessary in shell.
Thank you for coming back to me and I inherited this perl script to gather our errors onto our Nim server. I will look at combining the egreps together as you suggest and -m option doesnot make any sense so have removed that from my code and will look at your awk code and see if I can adapt it to get what I need.
Thanks for your help so far. I've tried putting the awk script into my Perl routine but I'm not sure if I'm missing something so please forgive my ignorance. This is my Perl code:
#my $errRpt = `ssh $hostname "grep -s -e '$shortDate' -e '$shortDate2' /var/log/messages|egrep -v 'ssh|cr
on|warn|segfault|success|syslog|passwd|usersense|command|patrol' \n"`;
my $errRpt = `ssh $hostname "awk -v SD1='$shortDate' -v SD2='$shortDate2' '
# Ignore things that don't match SD1 and SD2
!((SD1 ~ $0) || (SD2 ~ $0)) { next }
# Ignore things that match these strings
/ssh|cron|warn|segfault|success|syslog|passwd|usersense|[Pp][Aa][Tt][Rr][Oo][Ll]/ { next }
/multipathd/ {
STR=$0
# Blank the date fields for easier comparison
for(N=1; N<=5; N++) $N=""
# Skip messages that've happened before
if(U[$0]++) next;
# Put it back
$0=STR
}
1' /var/log/messages "`;
$errRpt =~ s/$hostname //g;
if ( $errRpt ne "" ) {
$message .= "###############################################\n";
$message .= "## Host $hostname\n";
$message .= "###############################################\n";
$message .= "TIMESTAMP DESCRIPTION\n";
$message .= $errRpt;
$message .= "\n";
}
and running it produces:
# ./test.pl
Global symbol "$N" requires explicit package name at ./test.pl line 74.
Execution of ./test.pl aborted due to compilation errors.
#
If I define $N within the script I still get errors:
# ./test.pl
bash: -c: line 2: syntax error near unexpected token `{'
bash: -c: line 2: `!((SD1 ~ ./test.pl) || (SD2 ~ ./test.pl)) { next }'
#
I am running the script on my AIX nim server which is to ssh onto the various Linux servers running a single command in it's shell - in this case the awk statement.
Can you advise please?
Thanks,
Neil.
---------- Post updated at 06:04 AM ---------- Previous update was at 04:47 AM ----------
Sorry, this is my test within the script:
#my $errRpt = `ssh $hostname "grep -s -e '$shortDate' -e '$shortDate2' /var/log/messages|egrep -v 'ssh|cr on|warn|segfault|success|syslog|passwd|usersense|command|patrol' \n"`; my $errRpt = `ssh $hostname "awk -v SD1='$shortDate' -v SD2='$shortDate2' ' # Ignore things that don't match SD1 and SD2 !((SD1 ~ \$0) || (SD2 ~ \$0)) { next } # Ignore things that match these strings /ssh|cron|warn|segfault|success|syslog|passwd|usersense|[Pp][Aa][Tt][Rr][Oo][Ll]/ { next } /multipathd/ { STR=\$0 # Blank the date fields for easier comparison for(N=1; N<=5; N++) \$N="" # Skip messages that've happened before if(U[\$0]++) next; # Put it back \$0=STR } 1' /var/log/messages "`;
And this is what I get when I run it so not sure if I've got the awk syntax correct within the Perl script.
# ./test.pl
bash: -c: line 2: syntax error near unexpected token `{'
bash: -c: line 2: `!((SD1 ~ sh) || (SD2 ~ sh)) { next }'
#
Hi guys, first of all apologize for my English...
I have a big problem with "Segmentation fault", when running my game server.
Console:
(gdb) bt full
#0 0x0000000000000000 in ?? ()
No symbol table info available.
#1 0x00007ffff702aca4 in std::basic_ostream<char,... (1 Reply)
Hi,
I want to do some fault association analysis in red hat linux. who can tell me where I can get all of the fault information, and the detailed description about this fault information.
Thank you very much. (4 Replies)
We have run software on Dell Servers w/ Windows and seen the performance degrade overtime. We switched to an IBM server w/ AIX and have not seen the same performance degradation over time. In fact, the IBM servers are at least five years old and continue to preform well at the same level.
How... (2 Replies)
Hi,
Operating System: Ubuntu 10.04
Other Packages Installed: freetds,DBI,DBD-Sybase
I am trying to connect to SYBASE using perl programming..But the moment I am executing my perl program it throws a SEGMENTATION FAULT error.
I have attached strace output for the same...
Thanks for... (1 Reply)
I would like to configure a bare minimum Linux with internet browser on a system with Flash & RAM (but no harddisk or any other nonvolatile storage). Please advise. (5 Replies)
Hello out there!!!
I have a Red Hat Entreprise Linux 4 server and I am encountering this error
# grep
Segmentation Fault
I know it is not the right use of grep command, but I did that just for testing purpose,then I did
# which grep
/bin/grep
# ls -l /bin/grep
-rwxr-xr-x 1 root... (4 Replies)