systemctl does not allow you to use environment variables.
I have a script that installs a program, downloads its system [email protected] file (note I cannot use a user service
, it needs to be a system service
which requires a username to be passed). It needs to run after boot, regardless which user logs in).
In order to do that, the script needs to enable the service like this:
sudo systemctl enable [email protected]
Normally, people would simply enter this command in terminal manually and use the name they want. But I am executing this script on multiple computers and I want the script to take care of it.
"username" should be the user that is logged in when this installation script runs. It is not root.
Normally, I would use the $SUDO_USER env variable as this simply returns the currently logged in user. Unfortunately you cannot use an env variable with systemctl
. I thought this would do the trick:
/bin/bash -c 'sudo systemctl start syncthing@$SUDO_USER.service'
But unfortunately that also does not work.
How can I solve this? Ubuntu 20.04.1