Manipulate application status with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Manipulate application status with awk
# 1  
Old 10-05-2015
Manipulate application status with awk

Hello Friends,

I am stuck with a silly (maybe simple) awk issue. I need to check some applications status and print to a file..

my application "rfe" status is like the following. I need to check each instance status for the following 4 rows..

Code:
sscm@SSCM-SFE1:~$  svcs -a | grep -iw rfe
online         Sep_01   svc:/application/rfe/rfe_master_1:default
online         Sep_01   svc:/application/rfe/rfe_master_2:default
online         Sep_01   svc:/application/rfe/rfe_reserve_3:default
online         Sep_01   svc:/application/rfe/rfe_reserve_4:default

I have written something like the following:

Code:
svcs -a | grep -iw rfe | nawk 'NR==1{if ($1==online);split($NF,a,"/");split(a[4],b,":"); printf("%s\n", b[1]" is "$1)}'

output:
Code:
rfe_master_1 is online

But as far as I understand, my first chec "if ($1==online)" does not have an effect on the result as I changed it as "if ($1==offline)" if prints the same result.

How could I solve it? should I use sprintf to store "$1" value to recall later?

regards
# 2  
Old 10-05-2015
man awk:
Quote:
Statements are terminated by newlines, semi-colons or both. Groups of statements such as actions or loop bodies are blocked via { ... } as in C.

The following statements control program flow inside blocks.

if ( expr ) statement
Your snippetif ($1==online); means "if yes do nothing". Remove the semicolon and "embrace" the split and print statements.

---------- Post updated at 15:40 ---------- Previous update was at 15:38 ----------

You know that you are operating on master_1 (or whatever comes in line # 1) only; "master_2" and "reserve_x" won't be touched at all?
# 3  
Old 10-05-2015
Thanks Rudic, I will remove the semicolon but when I embrace the two split and print statements with "{}" it does give nothing, did I misunderstand?

Right I need to check also NR==2, 3 and 4 too same columns and they are not included yet :/
# 4  
Old 10-05-2015
Heya

Code:
svcs -a | \
	sed s,[:/]," ",g | awk '/^online/ {print $6,"is",$1}'

Actually i wanted to try with substr, but this was quicker Smilie

hth
# 5  
Old 10-05-2015
Quote:
Originally Posted by EAGL€
.
.
.
Right I need to check also NR==2, 3 and 4 too same columns and they are not included yet :/
Make it NR<=4, then, or, if your input is four lines only, just drop the condition.

---------- Post updated at 17:30 ---------- Previous update was at 17:21 ----------

Did you compare $1 to the string "online" (must be in double quotes) or to the (undefined) variable online?

Last edited by RudiC; 10-05-2015 at 12:27 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk command to manipulate csv file in UNIX

Hi, I am new to awk and unix programming and trying to manipulate a csv file. My current csv file looks like this: col1,col2,col3,col4,col5,col4,col5,col6,col7,col8 223,V,c,2,4,f,r,,y,z 223,V,c,3,2,f,r,,y,z 223,V,c,1,4,f,r,,y,z 223,V,c,4,3,f,r,,y,z 227,V,c,3,1,f,r,,y,z... (8 Replies)
Discussion started by: Prit Siv
8 Replies

2. Shell Programming and Scripting

awk command to manipulate csv file in UNIX

Hi, I am new to awk/unix and am trying to put together a script to manipulate the date column in a csv file. I have file1.csv with the following contents: Date,ID,Number,Amount,Volume,Size 01-Apr-2014,WERFG,998,105873.96,10873.96,1342.11 01-Apr-2014,POYFR,267,5681.44,5681.44,462.96 I... (2 Replies)
Discussion started by: Prit Siv
2 Replies

3. Shell Programming and Scripting

Manipulate fields with AWK whose positions are changable

Hello Friends, I've been working with lots of different CDR-EDR files, before testing i need to manipulate my test files rather than requesting new files(to prepare them for next tests) which are different kind of CDRs,EDRs. In order to do this i might have to change more than a field in a... (3 Replies)
Discussion started by: EAGL€
3 Replies

4. Shell Programming and Scripting

wsadmin script using jython to check application server status in websphere

Hello All, I need a wsadmin script using jython to monitor server status in websphere. kindly help. (0 Replies)
Discussion started by: coolguyamy
0 Replies

5. Shell Programming and Scripting

Calculate application "not run" status

My shell env is Ksh88 , I need export the "not-running" application name. txt="abc001|abc002|abc003|abc004|xyz001|xyz002|cde004" IFS=\| app="" for i in $txt do appstatus $i # the command will return the status, 0 is not running, 1 is running if ] ; then # record the... (3 Replies)
Discussion started by: newoz
3 Replies

6. UNIX for Dummies Questions & Answers

Question on how to manipulate a SIMPLE text file (using awk?)

I have a simple txt files that looks something like this (The title is a part of the text file) Student Grades --------------- 1 Tim Purser 89 2 John Wayne 56 3 Jenn Hawkins 95 4 Harry Potter 75 Here are my questions: How would I ONLY print the names of students... (2 Replies)
Discussion started by: ninjagod123
2 Replies

7. Programming

Apache & nfs status from c++ application

Hello guys, I have just started building a high-available site using ubuntu server 9.10. I am using moodle. The thing is that i want to write an application using curses, to show the status of the apache servers, mysql servers and the nfs server. I can check the mysql from the c api, but how can... (1 Reply)
Discussion started by: pegasus001
1 Replies

8. Shell Programming and Scripting

How to print exit status in AWK

Hi all, How can I print the exit status in AWK? echo $? doesnt work for me Thanks (4 Replies)
Discussion started by: Pauline mugisha
4 Replies

9. Shell Programming and Scripting

Manipulate lines with sed/awk

Hey All, I need to reorganize a file's text. Here is the source: host John_Doe filename "config.cfg"; hardware ethernet 98:10:3d:13:8f:98; fixed-address 10.10.10.29; } host Jane_Doe filename "config.cfg"; hardware ethernet 98:13:11:fd:5a:57; fixed-address 10.10.5.24; } host... (2 Replies)
Discussion started by: TheBigAmbulance
2 Replies
Login or Register to Ask a Question