1

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.

ferg
  • 11
  • 2
  • 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. – berndbausch Jul 13 '21 at 07:13
  • @berndbausch if the organisation only accepts systemd, it probably only allows systemd timers, not `cron` jobs. – Stephen Kitt Jul 13 '21 at 08:13
  • 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 https://www.reddit.com/r/linuxquestions/comments/du0zke/is_there_a_systemd_equivalent_of_atatd/f70qlzb?utm_source=share&utm_medium=web2x&context=3 – muru Jul 13 '21 at 09:09

1 Answers1

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.

muru
  • 69,900
  • 13
  • 192
  • 292
  • Welcome to the site, and thank you for your contribution. Please note that [brevity is acceptable, but fuller explanations are better](https://unix.stackexchange.com/help/how-to-answer). Please consider editing the post to add more explanation on the mechanism and the various options used. – AdminBee May 24 '22 at 11:07
  • That's not what at does though. – Hamish Moffatt Jun 29 '23 at 06:06