Friday, 12 July 2013

How to send mail from shell scirpt?

Hi All,

First of all we will create a sh file and write script see example below:


Write down the following code in the above file:

dt=`date +%F`
echo $dt
count=`mysql -uipay_read -p$passwd -h localhost -D database_name -B --skip-column-names -e "select count(*) from tablename where last_execution_status = 'notexecuted' AND date(created_at) = '$dt';"`
if [ $count -ge 5 ]; then

echo $count;
mail   -s "$count Payment notifications are getting failed."  <<< 'There are $count notifications are pending due to cron job failure'

Now setting cronjob which will run every minute:

* * * * * /path/to/file/ipay4me_cronJob/ /usr/bin/php Asia/Calcutta >/dev/null 2>&1


No comments:

Post a Comment