Formatting the output of ps -eo command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting the output of ps -eo command
# 15  
Old 08-02-2012
yes we are, right this is the script as it stands, it sends an email now but only with the content I have echoed in before the awk command.

Code:
echo 'PRI    PID     USER    NICE    %CPU    COMMAND' >> /export/home/tjmoore/fi
le2
#
if ps -eo pri,pid,user,nice,pcpu,comm |awk 'BEGIN {found=1} {if($5>=5) {$1=$1; f
ound=0; print}} END {exit found}' OFS=$'\t'; >> /export/home/tjmoore/file2 2>/de
v/null
#
then /usr/local/bds/mailsend.s mailx "Process has surpassed 5% threshold" <email address> <email address> /export/home/tjmoore/file2 2&1>/dev/n
ull
fi
#

the actual ps ... output is displayed on the terminal screen and doesnt append to the file which I tell it to
# 16  
Old 08-02-2012
As stated before, you need to append a ; to the if statement, i.e. right before the then statement; I'm surprised there was no error msg.
Does the OFS=$'\t' do what it's meant to do, assign the <TAB> char you need in the output?

Just for the current, don't suppress errors, 2>/dev/null, let it show its errors!
This User Gave Thanks to RudiC For This Post:
# 17  
Old 08-03-2012
Im away from the system now Ill try this tomorrow, the tab output is working great now yeah

---------- Post updated 03-08-12 at 04:31 AM ---------- Previous update was 02-08-12 at 10:03 AM ----------

Looks like it is all working perfectly now! Smilie

cheers RudiC, I appreciate all the help you have provided

Finishing Script:

Code:
#!/bin/bash
#Send process which has exceeded 5%
#
#
echo 'The below is a list of processes which have exceeded the 5% threshold' > /
export/home/tjmoore/file2
#
echo ' ' >> /export/home/tjmoore/file2
#
echo 'PRI         PID         USER      NICE    %CPU    TIME     COMMAND' >> /ex
port/home/tjmoore/file2
#
if ps -eo pri,pid,user,nice,pcpu,time,comm |awk 'BEGIN {found=1} {if($5>=5) {$1=
$1; found=0; print}} END {exit found}' OFS=$'\t' >> /export/home/tjmoore/file2;
then /usr/local/bds/mailsend.s mailx "Process has surpassed 5% threshold" <email address> <email address> /export/home/tjmoore/file2 > 2&1>/dev
/null
fi
#

# 18  
Old 08-03-2012
I love it when a plan comes together
This User Gave Thanks to RudiC For This Post:
# 19  
Old 08-08-2012
hi, just looking at th script so I can learn and understand every part of it for future scripting, what does the
Code:
{found-1}

and
Code:
exit found

do?
# 20  
Old 08-08-2012
In your post #11 you said you found exit [ expr ] in your awk's man page. That's exactly what we are using here: exit found conveys awk's success or failure as its "exit status" to the shell for evaluation in the if construct, 0 representing success and 1 representing failure.
BEGIN {found=1} initialises the status to failure, but any line with percentage ($5) matching or exceeding 5 will set {found=0}, maybe repeatedly, so the conveying works.
This User Gave Thanks to RudiC For This Post:
# 21  
Old 08-09-2012
great cheers I understand that now Smilie

another one from an earlier post

Quote:
And yes, $1=$1 means field 1 = field 1, which is a dummy assignment that causes $0 to be modified and thus recreated. If $0 is not recreated, the <TAB> OFS will not be inserted.
Why does the $0 have to be recreated for the <TAB> OFS to work ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Output formatting

Hi , can anyone help me in this Input file Name= XYZ Company= ALPHA City= Stockhomn Equipment=computer Country=Sweden Name=MNC Company=Beta City=Kaulampur Equipment=computer Country=Malaysia Name=JVC Company=gamma City=Kiruna (3 Replies)
Discussion started by: swets
3 Replies

2. Shell Programming and Scripting

Formatting the output

Hi, I have a file which contents entries in this form. Only in /data4/temp abc.000001 Only in /data4/temp abc.000003 Only in /data4/temp abc.000012 Only in /data4/temp abc.000120 Only in /data4/temp abc.000133 Only in /data4/temp abc.001444 i want to read line by line and format... (2 Replies)
Discussion started by: arijitsaha
2 Replies

3. Shell Programming and Scripting

sql select command output formatting in shell script

Hi, I need to connect to the database and retrieve two variables from the database and store them in a variable,out of these two variables I need to get lastdigit appended to the variable 1 retrieved and variable 2 with out any modification in short select var,data from usage; o/p=... (1 Reply)
Discussion started by: rkrish
1 Replies

4. Shell Programming and Scripting

Output formatting .

below is a CPU utilization Log for ABC server. However for every 15 minutes it generates 3 CPU values(with interval of 2 sec). Host CPU CPUtotal CPU% time ABC 101.1 2 50.55 14 : 15 ABC 100.5 2 50.25 14 : 15 ABC 100.2 2 50.1 14 : 15 ABC 100.9 2 50.45 14 : 30 ABC 100.5 2 50.25 14 : 30 ABC... (5 Replies)
Discussion started by: pinga123
5 Replies

5. Shell Programming and Scripting

Output formatting

I have input file in this way John 1234 BASIC 26000 John 1234 ALLOWC 01550 John 1234 INCER 01700 John 1234 REL 20000 Debi 2345 BASIC 29000 Debi 2345 ALLOWC 01600 Debi 2345 INCR 01900 Debi 2345 REL ... (8 Replies)
Discussion started by: vakharia Mahesh
8 Replies

6. Shell Programming and Scripting

formatting output

my script is as follows cnt=`ps -ef |grep pmon|grep -v grep|awk 'END {{print NR}}'` cnt2=`ps -ef |grep tns|grep -v grep|awk 'END {{print NR}}'` if then if then rman target/ catalog recdb/recdb@recdb cmdfile report_need_backup.sql > report_need_backup.txt ... (1 Reply)
Discussion started by: swkambli
1 Replies

7. Shell Programming and Scripting

Formatting ls output

I am using find and ls to search for "warez" files on my server. find /home/ -regex ".*\.\(avi\|mp3\|mpeg\|mpg\|iso\)" -print0 | xargs -0 ls -oh This command produces this: -rw-r--r-- 1 1000 3.2M Feb 18 2009 /home/user/public_html/lupus.mp3 I want to only get this 3.2M... (4 Replies)
Discussion started by: bonrad
4 Replies

8. Shell Programming and Scripting

formatting the output

Is it possible to convert the attached file to the format mentioned. Here for a particular job the table name and the corresponding instance name from one test run "X" is compared with the table name and the instance name from the second test run "Y" for output rows,affected rows,applied... (1 Reply)
Discussion started by: ragavhere
1 Replies

9. Shell Programming and Scripting

Formatting output

Hi, I am new to shell scripting, I ahve written a shell script which would extract me data, but my problem is I want to add a column name to my output. Using grep and sed I am getting my data from the input file. Sample data name : eric name : tom name : sean My output using grep and sed... (3 Replies)
Discussion started by: illur81
3 Replies

10. Shell Programming and Scripting

Formatting the output

Hi all, Have the following code(1) producing the results(2 & 3). Would like to know if there is a way to format the two reports created in a similar fashion. IE - The first is formatted nicely as a result of the echo "$xmpbdate $xavgs" >> $xmpbrpt However when I attempt to do the same on... (7 Replies)
Discussion started by: Cameron
7 Replies
Login or Register to Ask a Question