This script is to send a email if the IP adress is active
when i run this script it is working and sending emails to external users in different domains, but when this script is scheduled in a cron it is unable to send the emails
#/bin/sh
ifconfig -a | grep 192.168.0.1
if [ $? == '0' ];
then mail -s "subject" mail.domain.com < /home/user/mailmessage.txt
fi
So i used a while loop avoding cron, Below is the code, This is able to send the emails,
#/bin/sh
while :
do
ifconfig -a | grep 3.229.224.157
if [ $? == '0' ]
then
mail -s "CRITICAL!! PAN Credit Application Load Balancing Has Failed Over to MYUKSLCAP2LB002" -c \
emailaddress@fqdn.com < \
/home/smg_prod/mailmessage.txt
fi
sleep 60
done
But for the same code why it is not able to send emails when set via cron, checked cronlogs and found no errors, cron is executed as schedules, also checked messages no errors found
Starting a script through cron is not the same as when being started from a shell manually. You should ensure that all binaries etc. are found since you have not the same environment as in your shell. PATH variable and others are not set if you do not set them explicitly.
Here is a general guide to cron with things noted you should take into account: