Need way to grep the following output in bold


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need way to grep the following output in bold
# 1  
Old 03-12-2018
Need way to grep the following output in bold

Hi guys,

i am not able to work this out, i need to write a script to monitor the usage of IO DISK READ whenever the IO is above 600MB it will send an email.

So far not able to. Hope you guys can assist me. Thanks!

Code:
[root@xxxx ~]# iotop -bot --iter=3 |grep DISK|egrep -v TIME
05:22:04 Total DISK READ :      20.70 M/s | Total DISK WRITE :    1157.23 K/s
05:22:04 Actual DISK READ:      14.53 M/s | Actual DISK WRITE:    1348.83 K/s
05:22:06 Total DISK READ :      24.51 M/s | Total DISK WRITE :    1067.07 K/s
05:22:06 Actual DISK READ:      22.92 M/s | Actual DISK WRITE:      10.54 M/s
05:22:07 Total DISK READ :      20.78 M/s | Total DISK WRITE :    1034.70 K/s
05:22:07 Actual DISK READ:      23.04 M/s | Actual DISK WRITE:       6.33 M/s
[root@xxxx ~]#

# 2  
Old 03-12-2018
And where did you fail?

BTW, I don't see any DISK READ above 600MB in your sample?
This User Gave Thanks to RudiC For This Post:
# 3  
Old 03-12-2018
Yes, i would like to set up an email monitoring whenever the DISK READ went above 600MB per second it will trigger an email to me personally.

I was able to get the output of 3 lines but not managed to create a logic when the read go above 600MB.

Code:
[root@xxxx ~]# iotop -bot --iter=3 |grep "Actual DISK READ"| awk {'print $5'}
127.99
151.71
157.06
[root@xxxx ~]#


ok using one second data might help.

Code:
[root@xxxx ~]# iotop -bot --iter=1 |grep "Actual DISK READ"| awk {'print $5'}
145.13
[root@xxxx ~]#

# 4  
Old 03-12-2018
Quote:
Originally Posted by jaapar
I was able to get the output of 3 lines but not managed to create a logic when the read go above 600MB.

Code:
[root@xxxx ~]# iotop -bot --iter=1 |grep "Actual DISK READ"| awk {'print $5'}
145.13
[root@xxxx ~]#

So, basically, you want to test, whether a number containing a decimal point is larger than 600?

If you are using Zsh as a shell, you have decimal arithmetic, and can simply compare the number you get numerically to 600. This is probably the most straightforward way.

If you are using a shell, which has only integer arithmetic, you can just remove everything starting from the dot, which in your example would leave you with 145, and if this is numerically greater or equal to 600, you are sending your email.

The third possibility is to move the logic into awk. Currently, you always output $5. You could print this only if $5 is numerically greater than 600. This means that whenever you get a non-empty output, you have to send the email.

Which approach you take, is just a matter of taste.....
This User Gave Thanks to rovf For This Post:
# 5  
Old 03-12-2018
Not sure I understand. To monitor, you want that script to run all day, i.e. 24/7? In what intervals? Will iotop allow for that, do you want to loop inside your script, or do you plan to schedule a cron job?
As a starting point, how far would this get you:
Code:
iotop -bot --iter=3 | awk  '/Actual DISK READ/ && $5 > 22 {system ("echo mail -s\\\"High disk IO: " $5 "\\\" user@host")} '
mail -s"High disk IO: 22.92" user@host
mail -s"High disk IO: 23.04" user@host

, echoing the mail command for testing, and adapted to use you sample from post#1.
This User Gave Thanks to RudiC For This Post:
# 6  
Old 03-12-2018
Thanks for helping out so far, your script did the job, but I was looking to find a write an if statement and schedule it in cron for every 15 minutes, something like below.

Code:
[root@xxxx ~]# cat write.sh
cmd1=`iotop -bot --iter=1 |grep "Actual DISK READ"| awk {'print $5'}`
if $cmd1 -ge 600; then
echo "Read IO is high" | /bin/mailx -s "Please check io usage" "user@host"
else
echo "io is fine"
fi
[root@xxxx ~]#

# 7  
Old 03-12-2018
Quote:
Originally Posted by jaapar
I was looking to find a write an if statement and schedule it in cron for every 15 minutes.
???? But I explained in my answer three choices you have for this, didn't I?

Still, I find the solution proposed by RudiC better.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep output

Hi. I have a command line that will generate exif data from .jpg files... So to get the Camera Model I use: find -iname "*.jpg" -print0 | xargs -0 exiftool -a | grep "Camera Model" But I want the file name AND the camera model... How to I get the grep to give me TWO bits of information from... (2 Replies)
Discussion started by: TuftyDave
2 Replies

2. UNIX for Dummies Questions & Answers

How to have the output in grep?

Hi guys - I am trying to have a certain file display information horizontally divided by a pipe. for example file name: foo.dat has information like this: name1 name2 name3 namenamename4 namene5 I would like it to display like this: name1|name2|name3|namenamename4|namene5 ... (6 Replies)
Discussion started by: DallasT
6 Replies

3. Shell Programming and Scripting

How to grep the desired output and output to a file?

currently I have process from a raw file to this stage ALTER TABLE "EXCEL_ADMIN"."TC_TXN_VOID" ADD CONSTRAINT "PK_TC_TXN_VOID" PRIMARY KEY ("TC_TXN_IID") ALTER TABLE "EXCEL_ADMIN"."TC_TXN_AMT" ADD CONSTRAINT "PK_TC_TXN_AMT" PRIMARY KEY ("TC_TXN_AMT_IID") ALTER TABLE... (10 Replies)
Discussion started by: jediwannabe
10 Replies

4. Shell Programming and Scripting

output text in bold font using SED

hi I want to write a script, while using the SED editor, to output the text, in this case a variable, to the result file but highlighted it in bold, is it possible to do that? can you tell me how? eg. in text.txt sed '$ a\ '$variable' ' <text.txt >text2.txt so it will add the... (2 Replies)
Discussion started by: piynik
2 Replies

5. Shell Programming and Scripting

grep output

hi i am running grep -c on a bunch of files some of which may be non existent. The output i get is in the same order as the files grep checks and this is what i want as i need to copy the output to a spreadsheet. However when i tried to pipe the output to sed to strip away the filenames and just... (5 Replies)
Discussion started by: chronics
5 Replies

6. Shell Programming and Scripting

grep output

From below mentioned line,i have to display output as last word only ie:arch_1_105366_720809746.dbf -rw-r----- 1 oracle dba 98887680 02 Mar 12:01 arch_1_105366_720809746.dbf Please .. (5 Replies)
Discussion started by: Sanal
5 Replies

7. UNIX for Dummies Questions & Answers

Help with grep output

Hello, I have a list of stings that I'm using with grep to determine which files contain the strings. Here's what I have now: list of strings in a file (list.txt): /directory/direc tory/file.jsp /dire ctory/directory/direct ory/file.jsp grep I'm doing to find files that contain the... (4 Replies)
Discussion started by: upstate_boy
4 Replies

8. Shell Programming and Scripting

GREP with contain output

How can I perform a grep and it will give me a contain word (maintenance) instead of a string or the whole line of info. grep with exclusive output? or is there a CONTAIN with IF statement ? I have a file call yast2_vhost.conf and it contain multiple entries call maintenance.html... (2 Replies)
Discussion started by: yoom@hostwebase
2 Replies

9. Shell Programming and Scripting

output of grep

hi, why the following is giving entire /etc/passwd file as output even when it does not contain ^ or $ . grep ' ' /etc/passwd whereas the following is not giving any output grep ' ^$ ' /etc/passwd (3 Replies)
Discussion started by: useless79
3 Replies

10. UNIX for Dummies Questions & Answers

How to underline/bold and how to align output

Hi, I work with AIX 5 and have two basic questions: 1) How do I underline/bold a word in a text output? Any way to do it with echo command? basic example: echo "FOLDER " >> folder.txt ( I wish the word FOLDER to be underlined and bold). 2) Suppose I have the following pipe delimited... (1 Reply)
Discussion started by: clara
1 Replies
Login or Register to Ask a Question