0

I have an user "postgres". And I want to run some cron job which should to work under it's account - "postgres". When it's running as a "postgres" then psql will automatically connect as a "postgres" user, without any passwords and similar...

I can do it easy with standard cron - just to add a cron job for the user "postgres". How to do it with systemd?

PS. I read that I have to create 2 "units": one for the timer and another one for the "job". But at the time - that the timer can work for active/logged-in users only. Sure, "postgres" user will not log-in. It won't be active. So, is it possible to do it with systemd, and if yes, please, show me how to achieve it.

2
  • sudo crontab -u postgres -e
    – Panki
    Mar 29, 2021 at 14:15
  • 1
    A common way to run a user's systemd unit even when the user is not logged in is to define it as a system unit. The User key in the Service stanza tells which user the service runs as. Of course, this requires you to have root privileges on the system. Would this be acceptable to you?
    – fra-san
    Mar 29, 2021 at 17:39

1 Answer 1

0

You want user timer unit. See https://www.freedesktop.org/software/systemd/man/systemd.timer.html

Example https://wiki.archlinux.org/index.php/Fdm#Systemd_Timer

1
  • will it work if the user "postgres" never logs in (is not active)?
    – RandomB
    Mar 29, 2021 at 16:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .