bash script

dpoper1 used Ask the Experts™

 My script does not see to work properly, I would appreciate your input in order to make it work. Thanks in advance.



[[ $1 = "" ]] && echo "The correct syntax is ./lbctl servername"
[[ $1 = "" ]] && exit

#Find out where the server is located
data=`wget -q ${LBPR1} -O - | grep $svr | awk -F"lb_node" '{print $2}' | awk -F"\"" '{print $1}' | wc -l`
dat2=`wget -q "${LBPR1}?cmd=edit&from=list&w=lbstore_lb&att=wa" -O - |  tr '\n' ' ' | sed 's/lb_node/\n&/g'| grep "lb_node${data}<"| awk -F"input name=" '{print $2}' | awk '{print $1}' | sed 's/\"//g'`
if [ ${data} -gt 1 ];then
       echo -n "Please enter 0 to take server out of the loop"
       echo -n "Please enter 1 to put server back in the loop"
               if [ $1 -eq 0 ] ; then
                        curl --silent POST "${LBPR1}/jkstatus?cmd=update&from=list&w=bfstore_lb&att=wa&re=10&val${dat2}=2"
                        curl --silent POST "${LBPR1}/jkstatus?cmd=update&from=list&w=bfstore_lb&att=wa&re=10&val${dat2}=0"

[[ $data = "" ]] && {
echo "sorry, $svr does not look like it is part of a jk group"

echo "$svr $dat2"

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Can you be more specific about which part of it is failing and how?


ok, here is my issue,

The purpose of this script is for me to enter the script with the servername:

 ./myscript servername

Then it will go out to multiple load balancers, and where it finds it; the script should prompt the user to take the server in and/or out of the loop. That portion is where the script is failing, it reads throughout the script and it does not prompt me for the action to perform, take a server in/out of the loop.

I would appreciate your input.

 data=`wget -q ${LBPR1} -O - | grep $svr | awk -F"lb_node" '{print $2}' | awk -F"\"" '{print $1}' | wc -l`

This should be:

  data=`wget -q ${LBPR1} -O - | grep $1 | awk -F"lb_node" '{print $2}' | awk -F"\"" '{print $1}' | wc -l`

You're grepping for $svr, but there's no such variable, so it will always be null, and always return 0 after piping through wc -l.

Then of course, it will never enter your loop at line 13.
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.


Thank you, that worked, now, I have a quick question, out of the output below, how would you get the actual number of the myservers_node20, I would only need to extract the number "20" out of the entire 1 liner.

I would appreciate your input.
<td>[<a href="/jkstatus?cmd=edit&amp;from=list&amp;w=bfstore_lb&amp;sw=myservers_node20">E</a>|<a href="/jkstatus?cmd=reset&amp;from=list&amp;w=bfstore_lb&amp;sw=myservers_node20">R</a>]&nbsp;</td><td>myservers_node20</td><td>ajp13</td><td>vmapp220:11009</td><td></td><td>ACT</td><td>OK</td><td>0</td><td>2</td><td>3</td><td>109</td><td>18809</td><td>0</td><td>101</td><td>0</td><td> 46M</td><td>2.7G</td><td>3</td><td>9</td><td>myservers_node20</td><td>&nbsp;</td><td>group16</td><td>0/0</td></tr>

Open in new window

Are you talking about finding the string "myservers_node20" and then pulling the 20 out of that?


Yes, I just need to pull out the numbers out could be a single double or triple
It's a bit ugly, but this should do what you need regardless of how many digits are in the output:
yournum=`echo $data | sed s,"</td>","\n",g | head -2| tail -1 | tr [a-z] "\n" | tail -1`

Open in new window


Thank you for your assistance, that helped.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial