I am writing a script to check the status of WAS server to confirm if the server is STARTED or FAILED to start. The server has 2 JVMs. So to check that either of the JVMs are up or not I am using the uniq command.
Lets say JVM1 got FAILED and JVM2 is STARTED, so the below command
sh /home/wasprofile/`hostname`/bin/serverStatus.sh -all > /tmp/ServerState
grep "Application Server" /tmp/ServerState|awk '{print $7}'|uniq
will show the output as:
FAILED
STARTED
So now how should i assign this output to two different variables in runtime ?? I mean something like this:
a=FAILED
b=STARTED
Any help on this is really appreciated.
You can use read
with process substitution:
read a b < <(awk '/Application Server/ && !seen[$7]++{printf "%s ", $7}' /tmp/ServerState)
PS: You can avoid grep
and uniq
both using awk.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.