如何设定crontab在每月最后一天执行一种方法:
for Linux
0 8 28-31 * * [ `date -d tomorrow +\%e` -eq 1 ] && do-something
for 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
.... # other codes start from here
本文介绍如何配置crontab使其能在每月的最后一天执行特定任务。提供了两种实现方式,一种是直接通过crontab进行条件判断,另一种则是将判断逻辑封装进shell脚本中,再由crontab调用。

5267

被折叠的 条评论
为什么被折叠?



