ConditionTimestamp=Thu 2015
-
08
-
13 14:31:11 CST
# timer
这个
unit
启动
时间
[root@study ~]#
systemctl show
backup.service
ExecMainExitTimestamp=Thu 2015
-
08
-
13 14:50:19 CST
# backup.service
上次
行的
时间
[root@study ~]#
systemctl show backup.timer
NextElapseUSecMonotonic=2d 19min 11.540653s
#
下一次
行距离
timers.target
时间
如上表所示,我上次执行
backup.service
的时间是在
2015-08-13 14:50
,由于设定两个小时执行一
次,因此下次应该是
2015-08-15 14:50
执行才对!
由于
timer
是由
timers.target
这个
unit
所管理
的,而这个
timers.target
的启动时间是在
2015-08-13 14:31
要注意,最终
backup.timer
所纪录的
下次运行时间,其实是与
timers.target
所纪录的时间差!因此是『
2015-08-15 14:50 - 2015-08-13
14:31
』才对!
所以时间差就是
2d 19min
啰!
.
一个固定日期运作的案例
上面的案例是固定周期运作一次,那如果我希望不管上面如何运作了,我都希望星期天凌晨
2
点运
作这个备份程序一遍呢?请注意,因为已经存在
backup.timer
了!
所以,这里我用
backup2.timer
做区隔喔!
[root@study ~]#
vim /etc/systemd/system/backup2.timer
[Unit]
Description=backup my server timer2
[Timer]
OnCalendar=Sun *
-
*
-
* 02:00:00
Persistent=true
Unit=backup.service
[Install]
WantedBy=multi
-
user.target
[root@study ~]#
systemctl daemon
-
reload
[root@study ~]#
systemctl enable backup2.timer
[root@study ~]#
systemctl start backup2.timer
[root@study ~]#
sy
stemctl show backup2.timer
NextElapseUSecRealtime=45y 7month 1w 6d 10h 30min
与循环时间运作差异比½大的地方,在于这个
OnCalendar
的方法对照的时间并不是
times.target
启动时间,而是
Unix
标准时间!
亦即是
1970-01-01 00:00:00
去比½的!因此,当你看到最后出现
NextElapseUSecRealtime
时,哇!下一次执行还要
45
+ 7
个月
+ 1
+ 6
+ 10
小时过
30
分~刚看到的时候,鸟哥确实因此揉了揉眼睛~确定没有看错
...
这才了½原来比对的是『日历时
间』而不是某个
unit
的启动时间啊!呵呵!