crontab 每月最后一天执行脚本

/usr/local/php56/bin/php /home/www/itbaoxiu/cli.php Api/WmsOrder/checkEasRpReceive

在linux中设置crontab在每月最后一天执行的几种方法:

方法一:
Linux环境:
0 8 28-31 * * [ `date -d tomorrow +\%e` -eq 1 ] && do-something
other Unix,BSD环境:
0 8 28-31 * * [ `echo \`cal\` | awk '{print $NF}'` -eq 1 ] && do-something


方法二:
单独靠crontab判断比较复杂,所以把判断部分写到执行脚本中
#!/bin/bash
today=`date +%d`
last_day=`cal | xargs | awk '{print $NF}'`
if [ "$today" != "$last_day" ]; then
exit 1
fi


方法三(最low但是实用)from zhd:
#!/bin/bash
date_arr=(01-31 02-28 02-29 03-31 04-30 05-31 06-30 07-31 08-31 09-30 10-31 11-30 12-31)
today=`date +%m"-"%d`
echo $today
for i in ${date_arr[@]}
do
        if [ $today == $i ]
        then
                echo $today"------start"
                /usr/local/php56/bin/php /home/www/itbaoxiu/cli.php Api/WmsOrder/checkEasRpReceive
                echo $today"------end"
        fi
done