Welcome to the IP Check Program!! Please input the ip address: 300.500
pingips.sh: line 19: [: echo $ip | cut -d. -f$i: integer expression expected
pingips.sh: line 19: [: echo $ip | cut -d. -f$i: integer expression expected
pingips.sh: line 19: [: echo $ip | cut -d. -f$i: integer expression expected
pingips.sh: line 19: [: echo $ip | cut -d. -f$i: integer expression expected
IP address is alive
Thank you for using the IP Check Program. \nPress 0 to exit and any other number to
continue
could someone please help me out? this is the error displayed. i guess why the program is messed up. because "300.500" is obviously not a valid ip address but it reads it as alive. PLEASE HELP! My code is below
#!/bin/bash
rs=1
while [ $rs -gt 0 ]
do
clear
#greet the user and request input
echo -n "Welcome to the IP Check Program!! Please input the ip address: "
read ip
#check user's input is IP address format
isIP="expr match $io'[0-9]\+\.[]0-9\+\.[0-9]\+\.[0-9]\+";
isIP=$?
if [ $isIP -eq 0 ];
then
isValid=1
for i in 1 2 3 4
do
n='echo $ip | cut -d. -f$i'
if [ "$n" -gt 255 -o $n -lt 0 ];
then
echo "INPUT ERROR. IP ADDRESS DIGITS SHOULD BE BETWEEN 0 AND 255
ONLY"
isValid=0
fi
done
if [ "$isValid" -eq 1 ];
then
echo "IP address is alive"
fi
else
echo "IP address is not responding"
fi
#greet user after using program
echo -n "Thank you for using the IP Check Program. Press 0 to exit and any other number
to continue"
read rs