如何指导cron每隔一周执行一次工作? [英] How to instruct cron to execute a job every second week?

查看:3779
本文介绍了如何指导cron每隔一周执行一次工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过cron运行一个工作,它将在每天的给定时间每隔一个星期二执行一次。每个星期二很容易:

I would like to run a job through cron that will be executed every second Tuesday at given time of day. For every Tuesday is easy:

0 6 * * Tue

但是如何在每个第二个星期二(或者如果你喜欢 - 每隔一周)?
我不想在脚本中实现任何逻辑,但是只保留cron中的定义。

But how to make it on "every second Tuesday" (or if you prefer - every second week)? I would not like to implement any logic in the script it self, but keep the definition only in cron.

推荐答案

crontab 即使在前五个字段中未完全定义

How about this, it does keep it in the crontab even if it isn't exactly defined in the first five fields:

0 6 * * Tue expr `date +\%W` \% 2 > /dev/null || /scripts/fortnightly.sh

这篇关于如何指导cron每隔一周执行一次工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆