Interpreting multiple values from a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Interpreting multiple values from a variable
# 1  
Old 12-23-2014
Interpreting multiple values from a variable

Hi,

I am writing a shell script which will check the status of a resource in a cluster and then display nicely to a user running the script at command line.

Basically the script runs a status command and then pulls certain keywords from the return and then should display a concise status.

My current code:

Code:
appVstatus=`scstat -g | grep ITM | grep $DC | awk '{print $2 "|" $5}'`
oldIFS="IFS"
IFS='|'
echo $appVstatus
 
    echo $appVstatus | (while read -r processname status; do
    echo "$processname is $status"
    done)

This results in :

Code:
CREST06QM_A_ITM Online
CREST06_HUBC3_A_ITM Online
CREST06_HUBC4_A_ITM Online
CREST06QM_A_ITM Online is 
CREST06_HUBC3_A_ITM Online is 
CREST06_HUBC4_A_ITM Online is

What I am actually looking for is:

Code:
CREST06QM_A_ITM Online
CREST06_HUBC3_A_ITM Online
CREST06_HUBC4_A_ITM Online
CREST06QM_A_ITM is Online 
CREST06_HUBC3_A_ITM is Online 
CREST06_HUBC4_A_ITM is Online

Any ideas would be gratefully received. I'm going round in circles on this one!
# 2  
Old 12-23-2014
Well I dont unsertans how you can achieve the first three lines of your desired output, but a quick look at your code makes me think CREST06QM_A_ITM Online is $processname and so the output I dont understand is where have the "is" passed in those lines (based on your code, if no $status is found, you should be left with "is" )
# 3  
Old 12-23-2014
Try read -r processname status RESTto avoid the rest of the line being read into the status variable.
# 4  
Old 12-23-2014
vbe - the first 3 lines are coming from the echo $appVstatus line (this was just a debug line to dislay what the variable contained).

RudiC - Still the same result.

It looks like the 2 prints in the AWK statement are being read into processname instead of the first to processname and the second to status

Last edited by chris01010; 12-23-2014 at 08:42 AM.. Reason: Terrible grammer
# 5  
Old 12-23-2014
Do you require information about resources or resources group or both ?
For resource groups :
Code:
 scstat -g | awk '$1 ~ /Group/ && $4 ~ /Online/ { print "RG" FS $2 FS "is online on host" FS $3 } '

For resources :
Code:
scstat -g | awk '$1 ~ /Resource:/ && $4 ~ /Online/ { print "Resource" FS $2 FS "is online on host" FS $3 } '

If you require both, i can work something out...
# 6  
Old 12-23-2014
I overlooked your setting IFS to "|" so my proposal was doomed to fail... Please post the output of scstat -g as I don't have that, so we can offer sensible help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read multiple values into one variable

Hello everybody, I am trying to assign multiple values from text into a single variable in bash. Source TXT: 1 THIS IS THE ENTITY1 NAME1 2 THIS IS THE ENTITY2 NAME2 3 THIS IS THE ENTITY3 NAME3 while read id entity name do printf "$id" "$entity" "$name" done <... (2 Replies)
Discussion started by: mrcrowley
2 Replies

2. Shell Programming and Scripting

Passing multiple column values to UNIX variable

sqlplus -s $USER_ID@$SID/$PWD<<EOF>sql_1.txt set feedback off set heading off select 114032 as c_1 from dual ; EOF for i in `cat sql_1.txt` do sh script_1.sh $i Currently i am passing one column value to the single unix variable. How can i pass the values from 2... (2 Replies)
Discussion started by: rafa_fed2
2 Replies

3. Shell Programming and Scripting

Variable with multiple values

Hello I need to alter a script to check for a flag file but there are now more than one type of flag file in my directory. Basically if any of these flg files exist then the MASK value should be set? Flag files to be included in assignment to variable e2e_scheduled*.flg COLL_STOP*.flg... (1 Reply)
Discussion started by: andymay
1 Replies

4. Shell Programming and Scripting

Removing multiple values from a variable

Hi I have a requirement like # e=`ls | grep -e"test" | awk -F " " '{print $1}'` (0) root @ ptxfv3: / # echo $e test test.xml From this i need to grep the word "test" alone i.e., it is occuring twice I need only one among them Please help (6 Replies)
Discussion started by: Priya Amaresh
6 Replies

5. Shell Programming and Scripting

Accepting multiple values in a variable at run time

Hi, Below is starting entry of my script #!/bin/ksh Usage() { print "Usage: $0 ID OPTION SERVER" print "<br>Where :" print "<br>Enter your ID into PARAM1, OPTION in the PARAM2 and SERVER in the PARAM3 field" print "<br>ID should be a valid ID" print "<br>OPTION should be either... (2 Replies)
Discussion started by: gopajitmalakar
2 Replies

6. Shell Programming and Scripting

storing multiple values in a array variable

Am using a find command in my script .The output may be one or more. I need to store those values in a array and need to access those. Am unable to find the solution . Any help on this will be helpful. if < code> else a=<find command output which gives the file name either 1 or more> if 1... (1 Reply)
Discussion started by: rogerben
1 Replies

7. Shell Programming and Scripting

help with assigning multiple values to a variable

I have a situation where my variable needs to pick up any of the 4 values from the environment it is in for e.g i am on server named a server=a (script running on this server) ftp servers= b c d e ----- the parameter passed should be any of these values in these 4 values, if not throw an... (4 Replies)
Discussion started by: dsravan
4 Replies

8. Shell Programming and Scripting

Using multiple values for single variable in a loop

Hello Guys, I have a small loop problem as below. I have 3 different values to be used while running the same script - va1="some-value1" va2="some-value2" va3="some-value3" Now I want to use these three variable values to be used for running the same command, like - while... (1 Reply)
Discussion started by: rockf1bull
1 Replies

9. Shell Programming and Scripting

Assigning multiple values to a variable

Hi Guru`s, I have to write a prog. which will traverse through diff. directories and then extract some data from files. I have written it and its working fine. But I have tested it in 1 folder. There are many folders and I need to loop through each of them. I am not sure abt the... (4 Replies)
Discussion started by: unx100
4 Replies

10. UNIX for Dummies Questions & Answers

Storing Multiple Values in a Variable

Hi, My code is as below: integer i=7 while ((i <= 5 )); do # test_out is a variable which contains data separated by "^". a= `echo $test_out | cut -d"^" -f$i` echo "$a" (( i = i + 1)); done From the above code, i kept $i after f so that i can capture all the data which is... (1 Reply)
Discussion started by: sandeep_1105
1 Replies
Login or Register to Ask a Question