linux - How to assign the output of uniq command to a variable in shell script -
i writing script check status of server confirm if server started or failed start. server has 2 jvms. check either of jvms or not using uniq command.
lets jvm1 got failed , jvm2 started, below command
sh /home/wasprofile/`hostname`/bin/serverstatus.sh -all > /tmp/serverstate grep "application server" /tmp/serverstate|awk '{print $7}'|uniq
will show output as:
failed started
so how should assign output 2 different variables in runtime ?? mean this:
a=failed b=started
any help on appreciated.
you can utilize read
process substitution:
read b < <(awk '/application server/ && !seen[$7]++{printf "%s ", $7}' /tmp/serverstate)
ps: can avoid grep
, uniq
both using awk.
linux bash shell
No comments:
Post a Comment