How to output the prstat into table and send through email?


 
Thread Tools Search this Thread
Operating Systems Solaris How to output the prstat into table and send through email?
# 1  
Old 03-01-2015
How to output the prstat into table and send through email?

Hi how to send below prstat script output into table format and send through email?

Code:
prstat|awk '{ if ($9 >= 5) print $0 }'


Last edited by Don Cragun; 03-01-2015 at 10:41 PM.. Reason: Add CODE tags.
# 2  
Old 03-01-2015
What exactly do you mean by "table format"?
# 3  
Old 03-01-2015
Quote:
Originally Posted by RudiC
What exactly do you mean by "table format"?
Mean like this prstat output tranform into table looks having borders.
# 4  
Old 03-01-2015
This is absolutely vague. A bit more care in specifying would NOT harm. Try
Code:
prstat |
awk     'NR==1  {COLS=NF
                 for (i=1; i<=COLS; i++) printf "+-------"
                 printf "+\n"
                }
                {gsub(/[         ]+/, "\t|"); print "|"$0"\t|"
                }
         END    {for (i=1; i<=COLS; i++) printf "+-------"
                 printf "+\n"
                }
        '
+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
|PID    |USERNA |USR    |SYS    |TRP    |TFL    |DFL    |LCK    |SLP    |LAT    |VCX    |ICX    |SCL    |SIG    |PROCESS/LWP    |
|1      |root   |0.0    |0.0    |-      |-      |-      |-      |100    |-      |0      |0      |0      |0      |init/1 |
|102    |root   |0.0    |0.0    |-      |-      |-      |-      |100    |-      |0      |0      |3      |0      |in.rdisc/1     |
|250    |root   |0.0    |0.0    |-      |-      |-      |-      |100    |-      |0      |0      |0      |0      |utmpd/1        |
|1185   |john   |0.0    |0.0    |-      |-      |-      |-      |100    |-      |0      |0      |0      |0      |csh/1  |
|240    |root   |0.0    |0.0    |-      |-      |-      |-      |100    |-      |0      |0      |0      |0      |powerd/4       |
|TOTAL: |71,    |load   |averages:      |0.02,  |0.04,  |0.08   |
+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+

# 5  
Old 03-01-2015
Quote:
Originally Posted by RudiC
This is absolutely vague. A bit more care in specifying would NOT harm. Try
Code:
prstat |
awk     'NR==1  {COLS=NF
                 for (i=1; i<=COLS; i++) printf "+-------"
                 printf "+\n"
                }
                {gsub(/[         ]+/, "\t|"); print "|"$0"\t|"
                }
         END    {for (i=1; i<=COLS; i++) printf "+-------"
                 printf "+\n"
                }
        '
+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
|PID    |USERNA |USR    |SYS    |TRP    |TFL    |DFL    |LCK    |SLP    |LAT    |VCX    |ICX    |SCL    |SIG    |PROCESS/LWP    |
|1      |root   |0.0    |0.0    |-      |-      |-      |-      |100    |-      |0      |0      |0      |0      |init/1 |
|102    |root   |0.0    |0.0    |-      |-      |-      |-      |100    |-      |0      |0      |3      |0      |in.rdisc/1     |
|250    |root   |0.0    |0.0    |-      |-      |-      |-      |100    |-      |0      |0      |0      |0      |utmpd/1        |
|1185   |john   |0.0    |0.0    |-      |-      |-      |-      |100    |-      |0      |0      |0      |0      |csh/1  |
|240    |root   |0.0    |0.0    |-      |-      |-      |-      |100    |-      |0      |0      |0      |0      |powerd/4       |
|TOTAL: |71,    |load   |averages:      |0.02,  |0.04,  |0.08   |
+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+

Hi RUdic,
Thanks for the reply. Sorry for less details. but return output like above for below filter where I only want to capture the process which use more than 5% CPU usage.
Code:
 prstat|awk '{ if ($9 >= 5) print $0 }'


Last edited by Don Cragun; 03-01-2015 at 10:42 PM.. Reason: Add CODE tags again.
# 6  
Old 03-01-2015
Quote:
Originally Posted by THARMENDRAN
Hi RUdic,
Thanks for the reply. Sorry for less details. but return output like above for below filter where I only want to capture the process which use more than 5% CPU usage.
Code:
 prstat|awk '{ if ($9 >= 5) print $0 }'

You say that you want to capture processes that use more than 5% of your system's available CPU power and then you show us code that captures processes that are sleeping (not using any CPU) 5% or more of the time.

Do you not understand that sleeping at least 5% of the time does not mean that that process is using 5% of your CPU. And, in particular, if the value in field 9 (sleeping) is 100 (which is greater than 5), it isn't using any CPU at all?

Are we also to assume that you want the headings removed from the table that RudiC's code provided. "SLP" when converted to a number in awk is 0 (which is less than 5)?

If you were to change the line:
Code:
                {gsub(/[         ]+/, "\t|"); print "|"$0"\t|"

in RudiC's code to:
Code:
         ($9 + 0) <= 95 {
                        gsub(/[         ]+/, "\t|"); print "|"$0"\t|"
                }

would that give you something you could use?

Of course, if you are running this on a Solaris/SunOS system, you need to use /usr/xpg4/bin/awk or nawk instead of awk (unless /usr/xpg4/bin comes before /usr/bin in $PATH).

And, as was noted in the other thread you started, basing any decision on one sample of prstat output is dangerous.
# 7  
Old 03-02-2015
Quote:
Originally Posted by Don Cragun
You say that you want to capture processes that use more than 5% of your system's available CPU power and then you show us code that captures processes that are sleeping (not using any CPU) 5% or more of the time.

Do you not understand that sleeping at least 5% of the time does not mean that that process is using 5% of your CPU. And, in particular, if the value in field 9 (sleeping) is 100 (which is greater than 5), it isn't using any CPU at all?

Are we also to assume that you want the headings removed from the table that RudiC's code provided. "SLP" when converted to a number in awk is 0 (which is less than 5)?

If you were to change the line:
Code:
                {gsub(/[         ]+/, "\t|"); print "|"$0"\t|"

in RudiC's code to:
Code:
         ($9 + 0) <= 95 {
                        gsub(/[         ]+/, "\t|"); print "|"$0"\t|"
                }

would that give you something you could use?

Of course, if you are running this on a Solaris/SunOS system, you need to use /usr/xpg4/bin/awk or nawk instead of awk (unless /usr/xpg4/bin comes before /usr/bin in $PATH).

And, as was noted in the other thread you started, basing any decision on one sample of prstat output is dangerous.
Hi Don Cragun,
Sorry for my mistake. When I do prstat in my SUN server the output as below:
PID|Username|Size|RSS|State|PRI|NICE|TIME||CPU|Process/NLWP

So when I need to capture CPU(field 9) usage more than 5%. I do below query.

prstat 5 1|awk '{ if ($9 >= 1) print $0}

So how can I produce the output of above code in table format(with border) as what shown by Rudic and send it through email?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell Script to read hive table and send email

HI Team, I am working on reading hive table and send email in email body using shell script, can you please help on fixing the errors: I have 6 columns in my hive table and trying to send the email in the mail body. below script: #!/bin/bash hive -e 'SELECT count(*) from db.table' >... (4 Replies)
Discussion started by: Mi4304
4 Replies

2. Shell Programming and Scripting

I want query output to send on mail using table tag and output should be in table

#! /bin/ksh #] && . ./.profile 2>/dev/null if test -f '.profile'; then . ./.profile; fi; #. .profile LOG_DIR=/app/rpx/jobs/scripts/just/logs sendEmail() { pzCType="$1"; pzTitle="$2"; pzMsg="$3"; pzFrom="$4"; pzTo="$5"; pzFiles="$6"; pzReplyTo="$7" ( ... (21 Replies)
Discussion started by: ankit.mca.aaidu
21 Replies

3. Shell Programming and Scripting

Shell scripting unable to send the sql query data in table in body of email

I have written a shell script that calls below sql file. It is not sending the query data in table in the body of email. spool table_update.html; SELECT * FROM PROCESS_LOG_STATS where process = 'ActivateSubscription'; spool off; exit; Please use code tags next time for your code and data.... (9 Replies)
Discussion started by: Sharanakumar
9 Replies

4. Shell Programming and Scripting

Parse qshape output and send email alert

Hi I need help to do this. This is the output of qshape: user$ qshape deferred|head T 5 10 20 40 80 160 320 640 1280 1280+ TOTAL 0 0 0 0 0 0 0 0 0 0 0 T stands for minutes elapsed and TOTAL... (1 Reply)
Discussion started by: zorrox
1 Replies

5. Shell Programming and Scripting

Send email if Output is available

hello can anyone debug these lines cd /usr/local/scripts ./build update ./build versions | grep available if then mail -s "update for server `hostname`" $EMAIL else echo -e "$YELLOW No update $RESET" fi echo "Please press a key - Back to main menu . . ." ; read but... (3 Replies)
Discussion started by: nimafire
3 Replies

6. Shell Programming and Scripting

How to send mails based on email ids residing in table?

Hello Gurus, I have one table which consists of two field:- PROG_NAME EMAIL xxxx email1,email2,email3 yyyy email4,email1,email2 I want to to send mails by using mailx command. But how do I get each and every mail ids from table against... (4 Replies)
Discussion started by: pokhraj_d
4 Replies

7. Shell Programming and Scripting

Send output of a command as an email

Hello Unix Experts! We are on AIX 6.1 TL6 I am trying to develop a script that does the following: It should send the output of "df -g /directory/folder" command as an email to a user(someone@company.com) This is too simple and i can research on how to do it, but it would be great if... (2 Replies)
Discussion started by: atechcorp
2 Replies

8. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

9. Shell Programming and Scripting

send an email of script output

Hi All, I'm trying to send some file which generated by script to my email. when I run the script I'm getting an email. Thats fine. But it seems to be all messed up like below Memory Status on ServerA: Mem: 3867444k total, 862680k used, 3004764k free, 54456k buffers!! CPU Status on ServerA:... (4 Replies)
Discussion started by: s_linux
4 Replies

10. Shell Programming and Scripting

Send one email with output result from 2 commands

Hi, i want to create a script which should do the following: 1) ping the remote servers and email the hosts which are down 2) netstat on port x on 2 server and email the result too. I want both results to be sent in the same email. I have few ideas but i can't finish it. Here... (4 Replies)
Discussion started by: varu0612
4 Replies
Login or Register to Ask a Question