I'm trying to set up a VPN gateway on my Raspberry Pi 4 using the 64-bit version of Pi OS. While I have the VPN working fine, every time I reboot, I have to manually run the command "protonvpn connect" to establish the connection. I attempted to automate this with a cron job using @reboot followed by sleep 60 and then the path to my script that contains the command. However, even though the script works fine when executed manually, it's not functioning through cron. I noticed an odd line in my cron status indicating "(no MTA installed, discarding outputs)". I'm not sure if cron is the appropriate solution for this or if I'm missing something specific. Any advice would be greatly appreciated!
3 Answers
If cron is causing too many issues, you might want to just uninstall it and use a systemd service instead. It's generally more reliable for this kind of task.
You might be running into issues because the command requires sudo permissions or the path isn't set correctly. It’s a good idea to run "where protonvpn" in the terminal to confirm its location, and then make sure your script points to that path.
I checked, and the path is correct. When I try to run it with sudo, I get a lot of errors that suggest the credentials are stored for my user, not root. But it works perfectly when I run it without sudo!
It sounds like cron might not be the best choice for your use case. Instead, consider creating a service script. That way, the service manager can handle dependencies more effectively. If protonvpn supports OpenVPN, you could also look into using that and set it up as a service for better results.
Sorry if this is a silly question, but can a service script run as a user rather than root? I believe the Proton CLI has issues running with root since the credentials are tied to my user account. Also, I'm currently using WireGuard!
Yes, service scripts can run as a user! Just ensure you configure the service file correctly to run under your user context.

That sounds like a good option! I’ll definitely give this a try.