issue while configuring a script in the cronjob

Hi all,

I have written the following script which will try pinging to almost 24 nodes and when the connectivity is down it sends me an alert saying the node is down. It also gets me a trace route information and a contact information.
When i run this script manually it actually works. But when i have assigned it in cronjob and when it gets executed it throws up mails for all 24 nodes saying all are done which is not the case when executing it manually. I suspect that the if condition b=$? seems not to be working in this case or in other words the value of b goes greater than zero which is again not happening int eh case of running the script manually. Can you suggest me on this?

Can you assist me in this. I am a bit confused on this as i have checked all the paths i have referred in the scripts.

NODEINFODIR=/ndm1/work/scripts/testdir/venki
cd $NODEINFODIR
i=1
while [ $i -le 24 ]
do
k=`cat /ndm1/work/scripts/testdir/venki/iplist|head -$i|tail -1`
echo $k
v=`ping $k|grep alive`
b=$?
echo $b >>dhadha
if [ $b -gt 0 ]
then
traceroute $k > "$NODEINFODIR/tracerouteinformationof$k.txt"
cat $NODEINFODIR/filename | grep $k | cut -f1-8 -d '' > "Contactinformationfor$knode.txt"
(echo "Node $k is down"; uuencode Contactinformationfor$knode.txt Contactinformationfor$knode.txt;uuencode tracerouteinformationof$k.txt
tracerouteinformationof$k.txt)| mailx -s " Node connectivity " venkita.venkatarama@gmail.com
else
echo " The connectivity is live "
fi
i=`expr $i + 1`
done

ya ofcourse $? won't work in your case since $? will return the exit status of privious command and your previous command is assing something to a variable which will always return 0
so write only

ping $k |grep alive >/dev/null
b=$?

Actually that was just to test the values i get. But even afte i remove that the error remains the same.

if you see the same script works while running manually but is is not in the case while it is set in cronjob .

Would there be a possible reason for it?

I would suggest a small change that should remove the issue with the exit command.

#v=`ping $k|grep alive`
#b=$?
#echo $b >>dhadha
#if [ $b -gt 0 ]
# # the '-c' option will return the number of times "alive" was found.
v=`ping $k|grep -c alive`
if [ $v -gt 0 ]