3

What is the best way of using systemd-run in place of a simple

sudo -u xxx at -f backupJ-447.cmd  03:10

Our org has gone systemd mad and no longer installs 'at', 'batch' and cron is depricated on our new systems. I need a way to scheule occasional "one-off" file copies to happen in the middle of the night. I tried the following

sudo systemd-run --unit=backupJ-477.cmd --on-calendar 03:10 sudo -u xxx  /home/me/backupJ-477.cmd

But the job is permanent and runs every night. If I delete the job its unit name is somehow still persistent and cant be reused. If I dont give it a unit name I end up with dozens of random unit or job numbers which I cant review to see what they do/did.

3
  • I remember seeing a man page for at that contained a paragraph under BUGS to the effect of "at should be implemented by cron". Therefore, use cron, and include code in the backup script that removes the crontab entry. Commented Jul 13, 2021 at 7:13
  • @berndbausch if the organisation only accepts systemd, it probably only allows systemd timers, not cron jobs. Commented Jul 13, 2021 at 8:13
  • 1
    You probably need to use the file date and time (--on-calendar 2021-07-14 03:10) to prevent systemd-run from running it repeatedly, according to reddit.com/r/linuxquestions/comments/du0zke/… Commented Jul 13, 2021 at 9:09

1 Answer 1

0
systemd-run --on-active=30 --timer-property=AccuracySec=100m sudo -u xxx  /home/me/backupJ-477.cmd

This will be executed after 30 seconds once.

2
  • Welcome to the site, and thank you for your contribution. Please note that brevity is acceptable, but fuller explanations are better. Please consider editing the post to add more explanation on the mechanism and the various options used. Commented May 24, 2022 at 11:07
  • That's not what at does though. Commented Jun 29, 2023 at 6:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.