You are not logged in.

#1 2018-01-15 21:23:37

slashviper
Member
Registered: 2015-11-11
Posts: 17

can't run bash script at startup

Hi,
i want to run a bash script at boot that looks like :
#!/bin/bash
sudo openvpn --config "/PATH.ovpn" --auth-user-pass "/PATH/auth-user-pass.txt"
exit

i've tried crontab and creating a desktop file in ~/user/.config/autostart/
but nothign seems working.

If i run the file from terminal it works perfectly.
Any clue?

Offline

#2 2018-01-15 21:37:11

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,746

Re: can't run bash script at startup

Generally speaking you want to redirect your stderr and stdout to something and check for errors there, for example

0 0 * * * bin/dropbox start >/tmp/stdout.log 2>/tmp/stderr.log

'sudo' certainly won't work, you need root cron, but again generally speaking if you need root cron, then you are probably doing something wrong.

edit: perhaps worth reading https://askubuntu.com/questions/464264/ … ly-at-boot

Last edited by brontosaurusrex (2018-01-15 21:58:19)

Offline

#3 2018-01-15 21:40:53

slashviper
Member
Registered: 2015-11-11
Posts: 17

Re: can't run bash script at startup

crontab looks a bit different:
@reboot sh PATH/VPN.sh

I would think anything triggered from crontab is sudo? Am I wrong? I'll try the logs , thanks.

Offline

#4 2018-01-15 21:43:53

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: can't run bash script at startup

I've never used openvpn but the package supplies some systemd unit files — have you tried enabling them?

sudo systemctl enable openvpn

Or perhaps:

sudo systemctl enable openvpn@wlan0

There is also the user option:

systemctl --user enable openvpn

But I've never used a VPN of any type so perhaps you should await the advice of somebody who has.

Offline

#5 2018-01-15 22:15:55

slashviper
Member
Registered: 2015-11-11
Posts: 17

Re: can't run bash script at startup

I have it half working if i add gksu to the .desktop file from .config/autostart folder but it asks for sudo credentials(as supposed to).
is there a way to grant sudo execution without entering passwords? sorry, noob here.

Offline

#6 2018-01-15 22:54:32

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: can't run bash script at startup

slashviper wrote:

is there a way to grant sudo execution without entering passwords?

Yes, try putting "grant sudo execution without entering password" into any half-decent search engine and you should find a good link.

I really don't think that is how it is supposed to be done though.

Offline

#7 2018-01-16 06:47:39

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: can't run bash script at startup

you should really go the systemd route outlined in post #4.

also, installing new software, it is always advisable to read its documentation.

Offline

#8 2018-01-16 08:14:13

slashviper
Member
Registered: 2015-11-11
Posts: 17

Re: can't run bash script at startup

Thanks for all the tips! i'll test the suggestion from post 4  and take it from there.

Offline

Board footer

Powered by FluxBB