Awk to search for sting in lines and then email.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk to search for sting in lines and then email.
# 1  
Old 10-17-2012
Awk to search for sting in lines and then email.

I'm trying to use awk in a script to search for a string number in a plist file.
basically its a plist that records the bandwidth usage, and if the number is greater than 3GB which is equals 3221225472 bytes, it will send me an alert by email.
here is the file:


Code:
=<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>bytesDown</key>
	<integer>3221225472</integer>
	<key>bytesUp</key>
	<integer>736779840</integer>
	<key>connectionType</key>
	<integer>1</integer>
	<key>downloadLimit</key>
	<real>3</real>
	<key>downloadLimitIncludesUploads</key>
	<false/>
	<key>monthStartDay</key>
	<integer>0</integer>
	<key>theDayToday</key>
	<string>171012</string>
	<key>todaysBytesDown</key>
	<integer>654514353</integer>
	<key>todaysBytesUp</key>
	<integer>47922291</integer>
</dict>
</plist>


Thanks,
M

Last edited by Scrutinizer; 10-17-2012 at 12:43 PM.. Reason: code tags
# 2  
Old 10-17-2012
Try

Code:
if [[ $(awk -F "[<>]" '/bytesDown/{getline;if($3 > 3221225472){print $3}}' file) ]]
then
#sendmail - write ssend mail function here
fi

This User Gave Thanks to pamu For This Post:
# 3  
Old 10-17-2012
Code:
a=$(awk -F"[<>]" '/bytesDown/{a=1}a&&/integer/{if($3>3221225472){print "High";exit}}' plist.txt)
if [ "$a" = "High" ]
then
          echo "Usage is High" | mailx -s "Usage is high" abcd@xyz.com
fi

This User Gave Thanks to itkamaraj For This Post:
# 4  
Old 10-17-2012
Code:
size_GB=`awk -F "[<>]" '/bytesDown/{getline; { printf("%.1f",$3/1024/1024/1024); }} ' plist.txt`
threshold=3.0

if [[ $size_GB > $threshold ]]
then
        # Send Email
else
        :
fi

This User Gave Thanks to Yoda For This Post:
# 5  
Old 10-17-2012
Thank you very much,, all of them works

Last edited by ivaldiz; 10-17-2012 at 12:55 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

(n)awk: print regex search output lines in one line

Hello. I have been looking high and low for the solution for this. I seems there should be a simple answer, but alas. I have a big xml file, and I need to extract certain information from specific items. The information I need can be found between a specific set of tags. let's call them... (2 Replies)
Discussion started by: Tobias-Reiper
2 Replies

2. Shell Programming and Scripting

Search pattern on logfile and search for day/dates and skip duplicate lines if any

Hi, I've written a script to search for an Oracle ORA- error on a log file, print that line and the .trc file associated with it as well as the dateline of when I assumed the error occured. In most it is the first dateline previous to the error. Unfortunately, this is not a fool proof script.... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. Shell Programming and Scripting

Search and email

Hi, I have logs where I have to check this logs for the particular string for every 3 hours and send email alert if that string found in that log Did anybody have the shell script to do this. :cool: (9 Replies)
Discussion started by: manju98458
9 Replies

4. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

5. Shell Programming and Scripting

awk how to search strings within a file from two different lines

Hi, i would really appreciate any help anyone can give with the following info. Thanks in advance. I need to run a search on a file that contains thousands of trades, each trade is added into the file in blocks of 25 lines. i know the search has to take place between a time stamp specified... (4 Replies)
Discussion started by: sp3arsy
4 Replies

6. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

7. Shell Programming and Scripting

How to grep sting (*) ?

Hi all, I am trying to grep something from log file. For example. i need to grep sting = "*834*1" My LOG 2010-05-05 09:27:57,649|3|ABCD834|192.168.38.72|2365|444850623031|0|8|-|0|*834*1*1499413*00853662524#|470540.7219101273026475158 2010-05-05... (3 Replies)
Discussion started by: ooilinlove
3 Replies

8. Shell Programming and Scripting

Assign a sting to a name?

i want to assign a anme for a string, i got the things below, but it doesn't work. MParc1=`` if then $MPrac1=`Prac1` # assign $MPrac1 to Prac1 else $MPrac1=`` #assigne $MPrac1 to nothing fi echo "${MPrac1} >>file Output: (if num is 0) Prac1 can you please... (6 Replies)
Discussion started by: mingming88
6 Replies

9. Shell Programming and Scripting

search and combine lines in awk

Hi All, I have 1 "keyword" file like this: 00-1F-FB-00-04-18 00-19-CB-8E-66-DF 00-1F-FB-00-48-9C 00-1F-FB-00-AA-4F .... and the 2nd "details" file like this: Wed Feb 11 00:00:02 2009 NAS-IP-Address = xxxxxxxxxxxxxxxxxx Class = "P1-SHT-AAA01;1233704662;4886720" ... (6 Replies)
Discussion started by: xajax7
6 Replies

10. Shell Programming and Scripting

awk/sed search lines in file1 matching columns in file2

Hi All, as you can see I'm pretty new to this board. :D I'm struggling around with small script to search a few fields in another file. Basically I have file1 looking like this: 15:38:28 sz:10001 pr:14.16 15:38:28 sz:10002 pr:18.41 15:38:29 sz:10003 pr:19.28 15:38:30 sz:10004... (1 Reply)
Discussion started by: floripoint
1 Replies
Login or Register to Ask a Question