I'm trying to start a script with systemd, when an user logs in. Nevertheless until now, it is not working the way I'd like. What I did:
I placed the following service in
[Unit] After=network.service After=network-online.target [Service] ExecStart=/usr/local/bin/autologinNordVPN [Install] WantedBy=default.target
/usr/local/bin/autologinNordVPN has this content:
#!/usr/bin/expect # Script for automatic login at nordvpn set timeout 10 set username "myusername\r" set credentialpass "mypassword\r" spawn nordvpn login expect "Email / Username: " send "$username" expect "Password: " send "$credentialpass" interact
/usr/local/bin/autologinNordVPN works, if I start it with
./autologinNordVPN (independent, whether I start it with a normal user or as user with sudoers right).
After booting the machine and logging in as user with sudoers right, I can connect to NordVPN - the service above executed the script. Fine until here.
If I log in as "normal" user without sudoer right, I cannot connect to NordVPN - so something went wrong. Therefore I tried to add the service above to the users systemd. I copied the loginNordVPN.service to
~/.local/share/systemd/user/ and I started the service with
systemctl --user enable loginNordVPN.service. (I also removed the service from the systemwide systemd before.)
After reboot and login it seems, that the script wasn't executed totally.
If I look into the journal with
journalctl --user | grep "nordv" I can see, that service was startet, but for what ever reason it doesn't work:
journalctl --user | grep "nordv" Dez 13 15:04:03 MYSYSTEM systemd: Started Login current user to nordvpn. Dez 13 15:04:03 MYSYSTEM autologinNordVPN: spawn nordvpn login
I tried to change the user service this way, which does not work:
[Unit] Description=Login current user to nordvpn [Service] StandardOutput=journal ExecStart=/usr/local/bin/autologinNordVPN [Install] WantedBy=default.target
And this try neigther works:
[Unit] Description=Login current user to nordvpn [Service] Type=oneshot RemainAfterExit=true StandardOutput=journal ExecStart=/usr/local/bin/autologinNordVPN [Install] WantedBy=default.target
What do I have to do, to get my service with the script working for any user?