bash script


 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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Can you be more specific about which part of it is failing and how?
dpoper1Author Commented:
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.
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

dpoper1Author Commented:
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?
dpoper1Author Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dpoper1Author Commented:
Thank you for your assistance, that helped.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.