Just learned of timers the other day, but I’m a cron guy, anybody out there using timers? Anything I’m missing out on?

  • e8d79@discuss.tchncs.de
    link
    fedilink
    arrow-up
    14
    ·
    edit-2
    2 days ago

    My number one reason for using systemd timers is just that I find it more readable than cron. Usually I want to run things daily, weekly or monthlyand systemd timers make that very easy.

    Here is an example:

    backup.timer

    [Unit]
    Description=Run backup database daily
    
    [Timer]
    OnCalendar=daily
    RandomizedDelaySec=10
    
    [Install]
    WantedBy=timers.target
    

    backup.service

    [Unit]
    Description=Backup database
    
    [Service]
    Type=oneshot
    ExecStart=/bin/bash /path/to/backupscript.sh
    

    Another great feature is that the output of the script is logged to journald which is very convenient when you are troubleshooting why your backup failed last night.

    • nous@programming.dev
      link
      fedilink
      English
      arrow-up
      4
      ·
      edit-2
      21 hours ago

      You can also easily see when the job last ran, if it was successful and when it will next run. As well as just trigger the service if you want it to run now.

    • Successful_Try543@feddit.org
      link
      fedilink
      arrow-up
      5
      ·
      1 day ago

      Usually I want to run things daily, weekly or monthlyand systemd timers make that very easy.

      While crontab also has keywords for @daily, @weekly and @monthly, the automatic logging of systemd is useful and your example shows that it additionally allows to specify delays. I don’t know how anacron handles the latter.