Help with a simple shell script
I am relatively new to scripting and was wondering if someone could help me with my dilemma. I use IBM WebSphere and the command I use is:
xsadmin.sh -p 11111 -bp 11111 -ch servername123 -routetable The output is an example of this: P: partition:83 - state:reachable - ipaddress:servername100 - zone:ZoneB > R: partition:83 - state:reachable - ipaddress:servername101- zone:ZoneA P: partition:84 - state:reachable - ipaddress:servername102 - zone:ZoneB > R: partition:84 - state:reachable - ipaddress:servername103 - zone:ZoneA P: partition:85 - state:reachable - ipaddress:servername104 - zone:ZoneA > R: partition:85 - state:reachable - ipaddress:servername105 - zone:ZoneB And so on. I need to condense the output of this file to send to SiteScope as a file with only values of either <0 or >0. Meaning, if the state:reachable it needs to appear as >0. if state:unreachable than the value needs to appear as <0. I basically need to find a way to remove all erroneous info and substitute the words state:reachable or state:unreachable with either <0 or >0. I have tried many different methods, awk, sed and grep but seem to come up short. Any help would be most appreciative and would be a great learning tool. Thanks! |
Not sure I understand ... is this what your looking for?
Code:
xsadmin.sh -p 11111 -bp 11111 -ch servername123 -routetable | awk 'BEGIN{OFS=FS="-"}{if($2 ~ /state:reachable/)$2 = "<0";if($2 ~ /state:unreachable/)$2 = ">0"}1' |
Quote:
So now the output looks like which is correct given the >0 means state:reachable. P: partition:197 ->0- ipaddress:servername101 - zone:ZoneA > R: partition:197 ->0- ipaddress:servername101 - zone:ZoneB P: partition:198 ->0- ipaddress:servername102 - zone:ZoneA > R: partition:198 ->0- ipaddress:servername102 - zone:ZoneB P: partition:199 ->0- ipaddress:servername103 - zone:ZoneA > R: partition:199 ->0- ipaddress:servername103 - zone:ZoneB How do I remove the rest of the output to make the data just look like this? >0 >0 >0 >0 >0 |
Code:
sed -e 's/.*state:reachable.*/>0/' -e 's/.*state:unreachable.*/<0/' |
Quote:
P: partition:197 - ipaddress:servername101 - zone:ZoneA > R: partition:197 - ipaddress:servername101 - zone:ZoneB P: partition:198 - ipaddress:servername102 - zone:ZoneA > R: partition:198 - ipaddress:servername102 - zone:ZoneB I just need for the data to look like: >0 >0 >0 or <0 <0 <0 I have to have it in a special format to upload to SiteScope. |
Try this one:
Code:
xsadmin.sh -p 11111 -bp 11111 -ch servername123 -routetable | awk '/state:reachable/{print "<0";}/state:unreachable/{print ">0";}' |
Quote:
>0 >0 >0 Right now the data appears as: P: partition:197 ->0- ipaddress:servername101 - zone:ZoneA > R: partition:197 ->0- ipaddress:servername101 - zone:ZoneB P: partition:198 ->0- ipaddress:servername102 - zone:ZoneA > R: partition:198 ->0- ipaddress:servername102 - zone:ZoneB P: partition:199 ->0- ipaddress:servername103 - zone:ZoneA > R: partition:199 ->0- ipaddress:servername103 - zone:ZoneB I don't need the other data. I have tried some sed commands to remove, but I don't know how to remove the random numbers associated with the output, for example the numbers which appear after partition:199 or server names with numbers, for example nc2sz2ecmas19 or nc3sz2ecmas10. |
Quote:
|
Quote:
|
Actually, if one or the other word, (un)reachable, is always on each line:
Code:
xsadmin.sh -p 11111 -bp 11111 -ch servername123 -routetable | awk '$0 = (/unreachable/?"<":">")0' |
Needs a little tweaking.
Thanks for your help so far on this, I received further clarification as
to what I need to do and I think it requires a little tweaking. For the ones that are "state:reachable" I don't need any value returned, or maybe a simple echo statement that says "reachable" or a numeric value of "-1". I can change it if necessary.. For the ones that are in "state:unreachable". I need a count of how many return like that. Say 5,6,7, or so on. So the output I am interested in is: -1 (good) or 5 (bad) This is the script so far that I have. For a reference point. #!/bin/sh export JAVA_HOME=/hosting/products/WebSphereU01/java #sets the environment in java #the values -p -bp and -ch will need to be altered according to what needs to be run. /hosting/ogsa/ogsa-6.1.0.5/ObjectGrid/bin/xsadmin.sh -p 11111 -bp 11111 -ch server0123 -routetable | sed -e 's/.*state:reachable.*/>0/' e 's/.*state:unreachable.*/<0/' > `date "+%y%m%d%H%M%S"`.txt This is the output it produces in its current form. It counts the number of hosts on the grid. I don't need this many as an output, Just the ones from above in that format. >0 >0 >0 And so forth. |
I don't understand, so you want it to print the number of "unreachable" lines if there are any, and print "-1" if there aren't any?
Do you still want the ">0" and "<0" written the the text file, like in your script in the above post? |
Quote:
0 (for reachable) 5 (for unreachable) |
Code:
grep state:unreachable | wc -l |
Quote:
|
All times are GMT -5. The time now is 11:34 PM. |