Sponsored Content
Top Forums Shell Programming and Scripting Help with Linux hardware fault script in Perl Post 302605401 by Corona688 on Wednesday 7th of March 2012 10:50:41 AM
Old 03-07-2012
Don't take this too harshly, but:

Code:
# Parts that are perl
# Parts that are shell

my $errRpt = `ssh $hostname "grep -s -e '$shortDate' -e '$shortDate2' /var/log/messages|egrep -v ssh|egrep -v cron|egrep -v 'su:'|egrep -v warn|egrep -v segfault|egrep -v success|egrep -v syslog|egrep -v passwd|egrep -v usersense|egrep -v -i patrol|egrep -v -m 10 multipath`;

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

Code:
# Line counts of programs of identical function and logic
$ wc -l perl-backup.pl backup.sh
  49 perl-backup.pl
  25 backup.sh

$

Anyway. About your logic, you can also bundle those handfuls of egrep -v's into a single

Code:
egrep -v 'thing1|thing2|thing3|thing4|thing5|...|thing9

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:

Code:
nawk -v SD1="$SHORTDATE1" -v SD2="$SHORTDATE2" '
# Ignore things that don't match SD1 and SD2
!((SD1 ~ \$0) || (SD2 ~ \$0)) { next }
# Ignore things that match these strings
/ssh|cronsu:|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

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.
 

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
SIEVESHELL(1)						User Contributed Perl Documentation					     SIEVESHELL(1)

NAME
sieveshell - remotely manipulate sieve scripts SYNOPSIS
sieveshell [--user=user] [--authname=authname] [--realm=realm] [--password=password] [--exec=script] [--execfile=file] server[:port] sieveshell --help DESCRIPTION
sieveshell allows users to manipulate their scripts on a remote server. It works via MANAGESIEVE, a work in progress. The following commands are recognized: list list scripts on server. put <filename> upload script to server. get <name> [<filename>] get script. if no filename display to stdout delete <name> delete script. activate <name> activate script. deactivate deactivate all scripts. OPTIONS
-u user, --user=user The authorization name to request; by default, derived from the authentication credentials. -a authname, --authname=authname The user to use for authentication (defaults to current user). -r realm, --realm=realm The realm to attempt authentication in. -p password, --password=password The password to use when authenticating to server. Note that this parameter can be seen in the process list. Use with caution! -e script, --exec=script Instead of working interactively, run commands from script, and exit when done. -f file, --execfile=file Instead of working interactively, run commands from file file and exit when done. REFERENCES
[MANAGESIEVE] Martin, T.; "A Protocol for Remotely Managing Sieve Scripts", draft-ietf-managesieve-03.txt, Mirapoint, Inc.; May 2001, work in progress. AUTHOR
Tim Martin <tmartin@mirapoint.com>, and the rest of the Cyrus team <cyrus-bugs@andrew.cmu.edu>. perl v5.14.2 2014-06-03 SIEVESHELL(1)
All times are GMT -4. The time now is 08:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy