如何每天复制到两个目的地中的另一个?

Ste*_*fan 7 cron copy

如何用 cron 做到这一点?

  • 今天: cp * ~/destination.0
  • 明天: cp * ~/destination.1
  • 明天: cp * ~/destination.0
  • 明天: cp * ~/destination.1

...等等。

任何帮助将不胜感激!

pLu*_*umo 6

一个班轮:

0 0 * * * cp /path/to/* /path/to/destination.$(( $(date -d $(date +%F) +%s)/(3600*24) % 2))
Run Code Online (Sandbox Code Playgroud)

解释:

$(( $(date -d 0:00 +%s)/(3600*24) % 2))
Run Code Online (Sandbox Code Playgroud)
  • 将在+%s今天的 0:00 ( -d 0:00)返回以秒 ( ) 为单位的时间戳。
  • 除以(3600*24)将返回 unix 纪元的天数。
  • %2 将在 unix 纪元开始后的奇数天或偶数天返回 0 或 1。