Bash scripting help?

Scarpozzi

Lifer
Jun 13, 2000
26,389
1,778
126
I'm not sure if Bash is the best to use for this. Basically, there's a program running on this system that tells me the status of a tomcat app. I wrote a bash script that executes the program and sends the output to a log file to run nightly in my crontab. I've then setup another script to email me the contents of that file. It works great.

What I want to do now is somehow filter the log file that I created and use the output to decide whether or not I get notified via Email. I need help figuring out the best way to parse the data to then put it through a >= test of some sort.

These are the two lines that I need to filter around. I only need to be Emailed when these numbers are above a certain number...say 100 or 1000. I just need notification that things are queuing up so I can fix whatever's wrong.
Current Total Bytes in System: 0
Current Messages in System: 0

Any ideas on the best way to do this? Would it be easier to do in perl? Thanks,

-Scar
 

Scarpozzi

Lifer
Jun 13, 2000
26,389
1,778
126
You can do it, you would just need to use something like cut to extract the numbers into their own variables first.

http://mywiki.wooledge.org/ArithmeticExpression
While I was walking into work today, I thought about extracting the number of messages into sed. It's really the only one that matters... It'd just take a lot of formatting to clear the extra lines that are displayed...about 10 or so. I may give that a try.

Thanks.

-Scar
 

Aluvus

Platinum Member
Apr 27, 2006
2,913
1
0
Would it be easier to do in perl?

Code:
m/Current Messages in System: (\d+)/ or die "Oh noes!\n";
print $1;

Or if you're being silly and doing something like using commas in the numbers:

Code:
m/Current Messages in System: ([\d,]+)/ or die "Oh noes!\n";
print $1;

Or if this is a log file that you append to rather than overwrite, and therefore you want the last instance:

Code:
m/.*Current Messages in System: (\d+)/ or die "Oh noes!\n";
print $1;

Optimized for my time, not execution time.
 

Khyron320

Senior member
Aug 26, 2002
306
0
0
www.khyrolabs.com
grep "Bytes in System:" tomcat.log | awk '{ if ($6 > 100) print "Bytes: " $6}'

awk $x prints the value from that colum.

To mail it just pipe it to sendmail

Or am I misunderstanding the question.
 

Scarpozzi

Lifer
Jun 13, 2000
26,389
1,778
126
grep "Bytes in System:" tomcat.log | awk '{ if ($6 > 100) print "Bytes: " $6}'

awk $x prints the value from that colum.

To mail it just pipe it to sendmail

Or am I misunderstanding the question.

That may be the simplest way... I'm still playing around with the core script to get the environmental variables set correctly for cron, but that's definitely a good starting point. Thanks.
 

Scarpozzi

Lifer
Jun 13, 2000
26,389
1,778
126
Update: Got everything working a few days ago when I had some free time. Just set the env vars for cron and everything's going great. I'll probably end up with 3 or 4 versions of this script to alert me to different problems within the system...thanks again-
 

slayer9019

Junior Member
Oct 24, 2010
10
0
0
grep "Bytes in System:" tomcat.log | awk '{ if ($6 > 100) print "Bytes: " $6}'

awk $x prints the value from that colum.

To mail it just pipe it to sendmail

Or am I misunderstanding the question.


^^ yup thats how I would do it
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |