.Net  

select to_char(add_months(last_day(sysdate) +1, -1), 'yyyymmdd'),to_char(last_day(sysdate)+1 , 'yyyymmdd') from dual ;

00 22  * *  *   [`echo \`cal\`|awk '{print $NF}'` -eq `date +\%d`] && do-something(每月月底做两个.sh文件,以防其中一个不执行成功时,另个起作用)
假设每月最后一天的8点10分执行your_cmd_fullname,则
[code]for ((i=1;i<=12;i++));do cal $i 2004|sed '/^$\|2004\|^Su.*/d'|sed -e :a -e 'N;s/\n/ /;ta'|sed 's/.* \([0-9][0-9]\)$/\1/';done|awk '{a[$0]=sprintf("%s,%s",a[$0],NR)}END{for(i in a)printf("10 8 %d %s * your_cmd_fullname\n",i,a[i])}' days|sed 's/ ,/ /'[/code]
执行结果
[code]10 8 29 2 * your_cmd_fullname
10 8 30 4,6,9,11 * your_cmd_fullname
10 8 31 1,3,5,7,8,10,12 * your_cmd_fullname[/code]
然后加入此段代码到你的crontab中
Linux---Shell:

#!/bin/bash
today=`date +%d`
last_day=`cal | xargs | awk '{print $NF}'`
if [ "$today" != "$last_day" ]; then
    exit 1
fi
....  # other codes start from here


如何在crontab中表达每月的最后一天,用表达式不行

每天执行,在要执行的程序头做判断,不是月末则退出

posted on 2007-09-10 21:53  东方新秀  阅读(324)  评论(0编辑  收藏  举报