So a little insight to what I am trying to achieve is I have multiple cells at a customer site. Each cell has the 3rd Octet of the IP corresponding to the cell ID. My bash script asks the user for an input (cell ID) and uses that stored var to populate the 3rd octet of the ping command. Though, it does not work, and not being familiar with bash I am somewhat at a loss.
The code I have wrote is:
echo Please input the station number.
read statNum
set e
echo “dev1, dev2, dev3, dev4, dev5, dev6, dev7, dev8, dev9, dev10, dev11, dev12"
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ”
ping -c 1 10.100.\“$statNum\“.1 | grep -c ‘ttl’ | tr ‘\n’ ‘,’ ;
ping -c 1 10.100.\“$statNum\“.2 | grep -c ‘ttl’ | tr ‘\n’ ‘,’ ;
ping -c 1 10.100.\“$statNum\“.3 | grep -c ‘ttl’ | tr ‘\n’ ‘,’ ;
ping -c 1 10.100.\“$statNum\“.4 | grep -c ‘ttl’ | tr ‘\n’ ‘,’ ;
ping -c 1 10.100.\“$statNum\“.5 | grep -c ‘ttl’ | tr ‘\n’ ‘,’ ;
ping -c 1 10.100.\“$statNum\“.6 | grep -c ‘ttl’ | tr ‘\n’ ‘,’ ;
ping -c 1 10.100.\“$statNum\“.7 | grep -c ‘ttl’ | tr ‘\n’ ‘,’ ;
ping -c 1 10.100.\“$statNum\“.8 | grep -c ‘ttl’ | tr ‘\n’ ‘,’ ;
ping -c 1 10.100.\“$statNum\“.9 | grep -c ‘ttl’ | tr ‘\n’ ‘,’ ;
ping -c 1 10.100.\“$statNum\“.10 | grep -c ‘ttl’ | tr ‘\n’ ‘,’ ;
ping -c 1 10.100.\“$statNum\“.11 | grep -c ‘ttl’ | tr ‘\n’ ‘,’ ;
ping -c 1 10.100.\“$statNum\“.12 | grep -c ‘ttl’”
done
I am returned with:
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o
ping: cannot resolve 10.100."2".1: Unknown host
0,ping: cannot resolve 10.100."2".2: Unknown host
0,ping: cannot resolve 10.100."2".3: Unknown host
0,ping: cannot resolve 10.100."2".4: Unknown host
0,ping: cannot resolve 10.100."2".5: Unknown host
0,ping: cannot resolve 10.100."2".6: Unknown host
0,ping: cannot resolve 10.100."2".7: Unknown host
0,ping: cannot resolve 10.100."2".8: Unknown host
0,ping: cannot resolve 10.100."2".9: Unknown host
0,ping: cannot resolve 10.100."2".10: Unknown host
0,ping: cannot resolve 10.100."2".11: Unknown host
0,ping: cannot resolve 10.100."2".12: Unknown host
0
script.sh: line 24: unexpected EOF while looking for matching `"'
script.sh: line 25: syntax error: unexpected end of file
In context, I know that "$statNum" within the 3rd octet of the IP is likely the improper data type and is being passed as a string, but I am not sure of the syntax to make it usable as the proper data type. Also, why am I getting a return for syntax error for matching " and unexpected EOF?
CodePudding user response:
10.100.\“$statNum\“.1
This way is wrong!
Try with:
10.100.${statNum}.1
Also you must use double or single quote and replace done with exit to the end of file.
echo 'Please input the station number.'
read statNum
set e
echo 'dev1, dev2, dev3, dev4, dev5, dev6, dev7, dev8, dev9, dev10, dev11, dev12'
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o "
ping -c 1 10.100.${statNum}.1 | grep -c 'ttl' | tr '\n' ',' ;
ping -c 1 10.100.${statNum}.2 | grep -c 'ttl' | tr '\n' ',' ;
ping -c 1 10.100.${statNum}.3 | grep -c 'ttl' | tr '\n' ',' ;
ping -c 1 10.100.${statNum}.4 | grep -c 'ttl' | tr '\n' ',' ;
ping -c 1 10.100.${statNum}.5 | grep -c 'ttl' | tr '\n' ',' ;
ping -c 1 10.100.${statNum}.6 | grep -c 'ttl' | tr '\n' ',' ;
ping -c 1 10.100.${statNum}.7 | grep -c 'ttl' | tr '\n' ',' ;
ping -c 1 10.100.${statNum}.8 | grep -c 'ttl' | tr '\n' ',' ;
ping -c 1 10.100.${statNum}.9 | grep -c 'ttl' | tr '\n' ',' ;
ping -c 1 10.100.${statNum}.10 | grep -c 'ttl' | tr '\n' ',' ;
ping -c 1 10.100.${statNum}.11 | grep -c 'ttl' | tr '\n' ',' ;
ping -c 1 10.100.${statNum}.12 | grep -c 'ttl' | tr '\n' ',' ;"
exit