Announcement

Collapse
No announcement yet.

Adjusting anacron/crontab timing with systemd

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Adjusting anacron/crontab timing with systemd

    I use a script in cron.daily to make my daily snapshots and weekly backups. For the longest time I wanted it to run earlier - at 5:30 am - but no matter what I did, it ran at 7:30 am. I've been using Linux forever and I certainly know how to amend crontab but it always stayed at 7:30.

    Turns out systemd changed a lot of things and this is one of them. Now systemd controls the cron job timing. This command:

    sudo systemctl edit --full anacron.timer

    reveals these contents:

    Code:
    [Unit]
    Description=Trigger anacron every hour
    
    [Timer]
    OnCalendar=*-*-* 07..23:30
    RandomizedDelaySec=5m
    Persistent=true
    
    [Install]
    WantedBy=timers.target

    Changing this line:
    Code:
    OnCalendar=*-*-* 07..23:30
    to this:
    Code:
    OnCalendar=*-*-* 05..23:30
    changed my daily time to 5:30

    This content is posted elsewhere on the web, but since it was a new discovery for me I thought I'd duplicate it here in case others ran into this issue.

    To see all your timers, run systemctl list-timers --all

    Output:
    Code:
    stuart@office:~$ systemctl list-timers --all
    NEXT                        LEFT          LAST                        PASSED       UNIT                         ACTIVATES                      
    Thu 2023-08-24 09:30:32 EDT 15min left    Thu 2023-08-24 08:33:32 EDT 41min ago    anacron.timer                anacron.service
    Thu 2023-08-24 09:44:54 EDT 29min left    Wed 2023-08-23 09:44:54 EDT 23h ago      systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
    Thu 2023-08-24 12:28:11 EDT 3h 12min left Thu 2023-08-24 05:47:02 EDT 3h 28min ago apt-daily.timer              apt-daily.service
    Thu 2023-08-24 14:44:29 EDT 5h 29min left Thu 2023-08-24 02:38:22 EDT 6h ago       fwupd-refresh.timer          fwupd-refresh.service
    Thu 2023-08-24 17:08:29 EDT 7h left       Thu 2023-08-24 09:15:04 EDT 19s ago      motd-news.timer              motd-news.service
    Fri 2023-08-25 00:00:00 EDT 14h left      Thu 2023-08-24 00:00:32 EDT 9h ago       dpkg-db-backup.timer         dpkg-db-backup.service
    Fri 2023-08-25 00:00:00 EDT 14h left      Thu 2023-08-24 00:00:32 EDT 9h ago       logrotate.timer              logrotate.service
    Fri 2023-08-25 06:28:19 EDT 21h left      Thu 2023-08-24 06:40:22 EDT 2h 35min ago apt-daily-upgrade.timer      apt-daily-upgrade.service
    Fri 2023-08-25 07:08:47 EDT 21h left      Thu 2023-08-24 05:08:22 EDT 4h 7min ago  plocate-updatedb.timer       plocate-updatedb.service
    Fri 2023-08-25 11:58:30 EDT 1 day 2h left Thu 2023-08-24 03:20:59 EDT 5h 54min ago man-db.timer                 man-db.service
    Fri 2023-08-25 15:08:36 EDT 1 day 5h left Thu 2023-08-24 02:06:22 EDT 7h ago       neon-apt-clean.timer         neon-apt-clean.service
    Sun 2023-08-27 03:10:49 EDT 2 days left   Sun 2023-08-20 03:10:36 EDT 4 days ago   e2scrub_all.timer            e2scrub_all.service
    Mon 2023-08-28 00:06:07 EDT 3 days left   Mon 2023-08-21 00:16:16 EDT 3 days ago   fstrim.timer                 fstrim.service
    
    13 timers listed.
    
    ​
    Last edited by oshunluvr; Aug 24, 2023, 07:16 AM.

    Please Read Me

    #2
    Thank you.

    Since you've had to get into systemd timers anyway, wouldn't it be simpler to migrate to using them only?
    Regards, John Little

    Comment


      #3
      Originally posted by jlittle View Post
      Thank you.

      Since you've had to get into systemd timers anyway, wouldn't it be simpler to migrate to using them only?
      But then I have to learn stuff...

      ...

      Please Read Me

      Comment

      Working...
      X