Need Help to add Condition in Shell Script..

Hi Team,
I m very new to shell scripting , i want to add following condition in my script .
Can anybody help me.

There are three port in My node "$port"

  • port_A
  • port_B
  • port_C

I Want to add following Conditions in my script.

  1. If Node is connected to port_A and port_B script should ask user where he want to run this script Y or N and then using user input run script.
  2. If Node is connected to port_C script will run continue

"NODE.SH" SCRIPT....

#exec > log_$node.log 2>&1
#set -x
> log_$node.log
IP=`command_system NODE_$node RTR:IP6:ADD | grep -i ".10B" | awk '{print$3}'`
port=`command_system NODE_$node RTR:IP6:ADD | grep -i ".10C" | awk '{print$2}' | cut -c 3- | rev | cut -c 5- | rev`

x="$( cut -d ':' -f8  <<< "$IP" )"
y="$( cut -d ':' -f7  <<< "$IP" )"
z="$( cut -d ':' -f1-6  <<< "$IP" )"
y=`echo $y | tr [a-z] [A-Z]`
y=`echo "ibase=16; $y+1" | bc`
y=`echo "obase=16; $y" | bc`
y=`echo $y | tr [A-Z] [a-z]`
NEWIP="$z":"$y":"$x"
p="$( cut -d ':' -f8  <<< "$NEWIP" )"
r="$( cut -d ':' -f1-7  <<< "$NEWIP" )"
p=`echo $p | tr [a-z] [A-Z]`
p=`echo "ibase=16; $p-1" | bc`
p=`echo "obase=16; $p" | bc`
p=`echo $p | tr [A-Z] [a-z]`
p="$r":"$p"

echo ":"
echo ":"
echo ":"
echo "Given NODE OMIP:     $NEWIP"
echo "Given NODE GWIP :     $p"
echo "CONCT  PORT      :     $port"
echo ":"
echo ":"
echo ":"
 
===============================================
Here want to add Condition
There are three "$port"
port_A
port_B
port_C
I Want to add following Conditions in my script.
I Want to add following Conditions in my script.
1.If Node is connected to port_A and port_B script should ask user where he want to run this script Y or N and then using user input run script.
2.If Node is connected to port_C script will run continue
===============================================

 
if ! fenew.sh $NEWIP $p $port
then
        echo "Telnet failed" >&2
        exit 1
fi
.
.
.
rm log_$node.log

Try

[ "$port" != "PORT_C" ] && { read -p"Do you want to run script? " ANS;    [ "${ANS^*}" == "Y" ] && . script; }
1 Like

Thanks But not working ...
getting "Do you want to run script?" prompt
and after input Y or N script will continue..

Need following Conditions in script.
1.If Node is connected to port_A and port_B script should ask user where he want to run this script Y or N and then using user input run script.
2.If Node is connected to port_C script will run continue without asking "Do you want to run script?" .

Thanks in Advance

Please read the proposal carefully. It does exactly what you specified: if PORT_A or _B, it asks the user and, if answer is y or Y , it sources a script called "script". If PORT_C, it does not ask and continues the original script.

If you're not happy, be way more precise and detailed in your specification.

---------- Post updated at 12:42 ---------- Previous update was at 12:40 ----------

Sorry, please use lower case "port_C" for the comparison.

1 Like

Hello Ganesh,

RudiC code is good, only thing please change PORT_C to port_C , it should work then I think.

Thanks,
R. Singh

1 Like

Hi,
Thanks for your help,it is working fine.

But If user detect port_B or port_A , How can he abort the script?
I want to to add this option also.

Don't call/source another script, exit the original script.

1 Like

Thanks for comment,yes your right .
But If user detect port_B or port_A i want to give both options to User

  1. He can Abort the script
  2. He can Continue the script

Sorry to bother u again , but i know very little about shell scripting.

Continue the original script OR run a new script? However, look into your shell's man page for the case statement.

1 Like

i want to continue the original script.

Try

[ "$port" != "PORT_C" ] && { read -p"Do you want to continue script? " ANS;    [ "${ANS^*}" != "Y" ] && exit; }
1 Like