Hi,
I wrote a script which generates a mail automatically under certain condition. When i execute the script manually in unix the script is getting executed and the condition works accordingly and the mail is also generated. But when it is pu into cron the mail is not generated and the condition also seems to be going wrong. The return code of the mail command is '1'. Please help me out.
Below is my sample format of my script,
#!/bin/sh
echo "The Job Successfully scheduled at : `date` "
cd **to some path**
ls **some condition** > filetmp.dat
while read line
do
grep $line file.dat > a1.dat
res=`echo $?`
echo "$res"
if [ $res = "1" ]
then
len=`echo $line | wc -c`
echo $len
if [ $len = "30" ]
then
subfile=`echo $line | cut -c1-18`
echo $subfile
cd **to some path**
grep TFS $subfile > a2.dat
tfs=`echo $?`
if [ $tfs = "0" ]
then
echo "FOUND"
else
echo "NOT FOUND"
while read address
do
echo "
Hi ,
This is an alert " | Mail -s "Test Mail" $address
echo "$? --> Mail Status for $address"
done < "addr.dat"
fi
elif [ $len = "44" ]
then
subfile=`echo $line | cut -c1-18`
echo $subfile
cd **to some path**
grep TFS $subfile > a2.dat
tfs=`echo $?`
if [ $tfs = "0" ]
then
echo "FOUND"
else
echo "NOT FOUND"
while read address
do
echo "
Hi ,
This is an alert " | Mail -s "Test Mail: " $address
echo "$? --> Mail Status for $address"
done < "addr.dat"
fi
else
subfile1=`echo $line | cut -c1-35`
echo $subfile1
cd **to some path**
grep TFS $subfile1 > a2.dat
tfs=`echo $?`
if [ $tfs = "0" ]
then
echo "FOUND"
else
echo "NOT FOUND"
while read address
do
echo "
Hi ,
This is an alert" | Mail -s "Test Mail:" $address
echo "$? --> Mail Status for $address"
done < "addr.dat"
fi
fi
fi
done < "filetemp.dat"
mv filetmp.dat file.dat
echo "The Job Successfully ended at : `date` "
Mail is not generated when scheduled into cron and the grep condition is not working when scheduled into cron. Please help me...