Sponsored Content
Top Forums Shell Programming and Scripting Help with Linux hardware fault script in Perl Post 302605644 by neilh1704 on Thursday 8th of March 2012 06:04:20 AM
Old 03-08-2012
Hello,

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 }'
#


Thanks
Neil.
 

8 More Discussions You Might Find Interesting

1. Red Hat

Segmentation fault on basic linux commands

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)
Discussion started by: inhaki
4 Replies

2. UNIX for Dummies Questions & Answers

Linux on custom hardware

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)
Discussion started by: rherb
5 Replies

3. Ubuntu

Ubuntu 10.04: Sybase with Perl Segmentation Fault

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)
Discussion started by: vnkatara
1 Replies

4. UNIX for Dummies Questions & Answers

With Linux do Hardware Brands Matter?

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)
Discussion started by: bggibson
2 Replies

5. Red Hat

Red Hat linux fault information

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)
Discussion started by: zhaoyy
4 Replies

6. Shell Programming and Scripting

Segmentation fault in Unix shell (linux OS)

Hi, I am trying to run an online downloaded tool but I am having an eror segmentation fault. ./multicoil test.seq Config file /home/kmohanas/MULTICOIL/multicoil_config window length 0 = 28 window length 1 = 28 multi_lib = 3 4 5 multi_lib = 2 3 4 pair_lib = 1 2 4 printfile =... (6 Replies)
Discussion started by: kaav06
6 Replies

7. Debian

Linux, Debian - Segmentation Fault problem.

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)
Discussion started by: Arson.
1 Replies

8. Hardware

Does this hardware works with Linux

Hello folks, I pretend acquire this hardware: 1-Motherboard Asus Skt1151 - H110M-A/M.2 (https://www.asus.com/pt/Motherboards...cifications/); 2-Intel i5 6400 2.7Ghz QuadCore Skt1151; or 2-Intel i5 6500 3.2Ghz QuadCore Skt1151; 3-Dimm 8GB DDR4 Kingston CL15 2133Mhz; Obvious I pretend... (1 Reply)
Discussion started by: enodev
1 Replies
CG(1)																	     CG(1)

NAME
cg - Recursively grep for a pattern and store it. SYNOPSIS
cg [ -l ] | [ [ -i ] pattern [ files ] ] DESCRIPTION
cg does a search though text files (usually source code) recursively for a pattern, storing matches and displaying the output in a human- readable fashion. It is intended to give some of the functionaly of AT&T's cscope(1) tool, with the advantages of simplicity and not being language-specific. The script will colorize output if configured as such. It is typically run with a Perl regular expression to search for. The search can be made case insensitive by using the -i option. A list of files may also be specified with an additional argument after the pattern. Put the files pattern in quotes to make it be matched by Perl rather than by the shell. Running the script with no arguments will recall the results of the previous search. After the search, entries found can be edited using the vg(1) script. The -l option shows the last log made. SOME EXAMPLES
cg - alone recalls the previous search results. cg -i pattern - search the default list of files for all files matching the pattern (and case-insensitively). cg pattern '*.c' - search recursively for pattern in all *.c files. This automatically converts '*' to '.*' and '.' to '.' for you and does a Perl pattern match on all files in the tree. cg pattern *.c - search through the shell-expanded list of *.c files, so not done recursively (in other words, only the files your shell pass to the script as arguments). cg -l - show the last log made. COMMAND-LINE OPTIONS -i Do a case-insensitive search. -l Show the last log made. -p Toggle the default pager option. cg has a bulit-in pager function, which can be enabled or disabled by default (in .cgvgrc). If the default is enabled, this option disables the pager; if the default is disabled, this option enables it. -P Force the built-in pager to be disabled. FILES
${HOME}/.cglast Log file of the last search. ${HOME}/.cgvgrc Per-user configuration file (if the defaults are not desireable). ${HOME}/.cgvg/* Log files in $HOSTNAME.shell_pid form with the log of the last search. SEE ALSO
vg(1), perl(1), find(1), grep(1), cscope(1) AUTHOR
cg was written by Joshua Uziel <uzi@uzix.org>. 13 Mar 2002 CG(1)
All times are GMT -4. The time now is 07:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy