Okay so I'm 13 and my dad set me a challenge of writing a program that check to see if a box is online with input parameter when starting the program so i came back with this.The top commented out bit is what he showed me how to do after i show him my code.
#!/bin/sh
#in=${@}
#tst=`echo ${in}|tr ' ' "Z"`
#if [ "${tst}" = "" ]; then
# echo "ERROR: Must provide some hosts as input to this script"
# exit 1
#fi
#for hostName in $in
#do
# ping -q -c 1 $hostName > /dev/null 2>&1
# if [ $? -ne 0 ]; then
# echo $hostName is offline
# else
# echo $hostName is online
# fi
#done
#exit 0
count=0
x=0
while [ $count -ne $# ]
do
if [ $count -eq 0 ]
then
x=$1
elif [ $count -eq 1 ]
then
x=$2
elif [ $count -eq 2 ]
then
x=$3
elif [ $count -eq 3 ]
then
x=$4
elif [ $count -eq 4 ]
then
x=$5
elif [ $count -eq 5 ]
then
x=$6
elif [ $count -eq 6 ]
then
x=$7
elif [ $count -eq 7 ]
then
x=$8
elif [ $count -eq 8 ]
then
x=$9
fi
ping -q -c 1 $x > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "$x is offline"
else
echo "$x is online"
fi
count=`expr $count + 1`
done
Is there any different ways of doing it??
:wall: