Visit Our UNIX and Linux User Community

Efficient rewrite of code?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Efficient rewrite of code?
# 1  
Old 12-30-2012
Efficient rewrite of code?

egrep -v "#" ${SERVERS} | while read shosts
                                grep -Pi "[a-z]|[A-Z]" ${LOGFILE} | egrep "${snhosts}" | egrep "NOTIFICATION:" | awk -F";" '{print $3}' | sort -n | uniq | while read CEXIST
                                        if [ "$CEXIST" = "$rcheckname" ] ; then
                                                echo "$CEXIST"

is there a better way to rewrite the above code? im guessing there's some awk magic out there that could work here?
# 2  
Old 12-30-2012
You need show us some samples on log file:


# 3  
Old 12-31-2012
LOGFILE is just a file with a list of hostnames, such as


# 4  
Old 12-31-2012
Presumably you mean that is content of the $SERVERS file? What is in the log files and what is in variable $rcheckname?
# 5  
Old 12-31-2012
Originally Posted by Scrutinizer
Presumably you mean that is content of the $SERVERS file? What is in the log files and what is in variable $rcheckname?
correct. my fault.

the log file contains hundreds of lines similar to:

[1356910980] SERVICE NOTIFICATION: AppEngAlerts;;PORT_5000_CHECK;CRITICAL;notify-by-email;CRITICAL

rcheckname is the name of a check. in this case, it would be PORT_5000_CHECK.

so, the if statement verifies the checkname found matches the one on record.

Last edited by Scrutinizer; 01-01-2013 at 02:54 AM.. Reason: removed code tags
# 6  
Old 01-01-2013
Not sure what you want to achieve. Inferring from pieces of info spread over the posts here and there, you want to check a log file against a list of servers to see if a certain check has been performed, and then output the check's name? You can do that like this:
$ grep -f servers $LOGFILE| grep "NOTIFICATION:.*$rcheckname" > /dev/null && echo $rcheckname 

Depending on the grep version the commented out server line might not be ignored in the search. What be the contents of ${snhosts}?

Last edited by RudiC; 01-01-2013 at 12:31 PM.. Reason: made a sentence more clear (tried to...)
# 7  
Old 01-01-2013
Or in bash or ksh93:
grep -f <(sed "/#/d; s/.*/NOTIFICATION.*;&;$rcheckname/" "$SERVERS") "$LOGFILE" |
cut -d\; -f2,3 | sort -u | cut -d\; -f2

awk '
NR==FNR && !/#/{
$2 in S && $0~pat && !O[$2]++{
  print $3
' pat="NOTIFICATION.*$rcheckname" "$SERVERS" FS=\; "$LOGFILE"

Last edited by Scrutinizer; 01-01-2013 at 10:41 AM..
This User Gave Thanks to Scrutinizer For This Post:

Previous Thread | Next Thread
Test Your Knowledge in Computers #309
Difficulty: Easy
FLAC stands for 'Free Lossless Audio Condenser';
True or False?

10 More Discussions You Might Find Interesting

1. Linux

Rewrite proxypass

Hi, I have a Apache 2.0 web server. When a users comes in to a check is applied if the path ends with *t*, the user hits a rewrite rule that adds an environment variable called x is hit with a proxypass. This has worked successfully in the past, but recently I added another rewrite... (0 Replies)
Discussion started by: 3junior
0 Replies

2. Shell Programming and Scripting

Efficient shell script code

Hi all, I am working on an extremely large collection of text data (about 2 million XML files) in a directory. I have changed the extension from .xml to .dat. Right now I am using this code to remove the XML tags, but the code is way too slow. It seems that it is taking fore-ever: #ls -1 *.dat... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

3. UNIX for Advanced & Expert Users

Sendmail Rewrite Ruleset

Hi all, I like to write a rule which do the following: INPUT ADDRESS REWRITTEN TO ----------------------------- ----------------------------- ... (1 Reply)
Discussion started by: bashily
1 Replies

4. Programming

Help with make this Fortran code more efficient (in HPC manner)

Hi there, I had run into some fortran code to modify. Obviously, it was written without thinking of high performance computing and not parallelized... Now I would like to make the code "on track" and parallel. After a whole afternoon thinking, I still cannot find where to start. Can any one... (3 Replies)
Discussion started by: P_E_M_Lee
3 Replies

5. Web Development

Need help with rewrite rule

Hi, I hosted my site on Apache web server. I wanted to redirect all the users request to a HTML page(maintenance page). I used the below rewrite rule to do ths same. RewriteEngine on RewriteRule .* /maintenance.html The maintenance.html page contains an image. When ever I try to... (2 Replies)
Discussion started by: BSrikanthB
2 Replies

6. Programming

Making FORTRAN code more efficient

Hi, I have a very large, very old FORTRAN code that I work with. The code is quite messy and I was wondering if I can speed up execution time by finding subroutines that code execution spends the most time in. Is there any kind of software I can use to see where the code spends most of the... (1 Reply)
Discussion started by: rks171
1 Replies

7. UNIX for Dummies Questions & Answers

rewrite date

I'm looking to have function that takes the present month and rewrites it into this form: _06_ (june), _09_ (september), and so on.. I would like this to be a my $this_month=code that rewrites date function because I would like to be a able to call it multiple times in the script by writing... (5 Replies)
Discussion started by: marringi
5 Replies

8. Shell Programming and Scripting

grep help, how do i rewrite this

Thanks , franklin you method worked, i knew i had to use a while loop and getline in there just didnt know the proper order :) Hi everyone, im trying to make the following command line shorter by introducing a script that join up all the grep commands ./new1a < numbers.txt | grep -i -v '^a '... (5 Replies)
Discussion started by: weezybaby
5 Replies

9. Shell Programming and Scripting

How do I rewrite to use a while instead of find?

for FILE in `find /home/Upload/*` Need to use a while instead to prevent errors when the file is emptied (4 Replies)
Discussion started by: goodmis
4 Replies

10. UNIX for Advanced & Expert Users

Apache Rewrite help!

I am trying to write RewriteRule on Apache_1.3.26 to get users web page from another server. for example if users tries to get web page on it will get the web page from without redirect and users will not be aware of any redirect... (1 Reply)
Discussion started by: hassan2
1 Replies

Featured Tech Videos