Below you can see my bash script
#createSession.sh
echo "Welcome to ADS2 Session Start..."
while [ true ]
do
echo "Starting service Daemon on the targert"
echo "Enter the ip-address of the target"
read x
if [ -z "$x" ]
then
echo "ip-address is empty"
else
echo "Connecting with target..."
if [[ $x =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]
then
ssh nvidia@"$x" "/opt/ads2/arm-linux64/bin/ads2 svcd&"
echo "connection succeded"
break
else
"Make sure the io address in the coorect form"
fi
fi
done
First question
As you see, the script checks if the user input machtes the ip-address form. However, i would like the script to also accept the ip address as a string which has this form fdt-c-agx-4arbitrary numbers. The last part of the string can be any arbitrary 4 numbers. As a result, the if statement be like
if [[ $x =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] || [ $x = #machtes fdt-c-agx-4arbitrary digits]
Second question
The ip address could be entered in the right form, however does not exist. Consequently, the ssh returns in this case ssh connection time out. However the string connection succeded will be printed which is not true. So how can i make the scripts enough clever to realize that the connection in this case is not established?
Thnaks in advance
As a result, the if statement be likeSoo... write it that way? You have^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$as an example, so just write the same that matches the other one.[0-9]means? I recommend regex crosswords, available on the net, to learn regex in no time.