You are not logged in.
Hi,
I;m trying to excute a command using ssh. It starts the command (that is a script) but stops half way. I just can't figgure out what i am overlooking.
/home/scripter/.ssh/authorised_keys:
command="/etc/VPN_restartQuick.sh" ssh-rsa AAAAB(etc)this allows me to run the command:
/etc/VPN_restartQuick.sh
#!/bin/bash
echo "Closing connection to OpenVPN "
sudo killall openvpn
sleep 2
echo "Connecting to OpenVPN "
cd /home/scripter/ #The login credentials are here in a login.conf file
sudo /usr/sbin/openvpn --config "/etc/openvpn/VPN/Recent.ovpn.tcp" --connect-retry 1 When i log into the console, and work as user "scripter" i can just execute /etc/VPN_restartQuick.sh and it works wonderfully. However, if i start it from a other computer using the ssh command: ssh -i ~/.ssh/id_rsa_pi scripter@pi3 it does the first part of the opperation perfectly and kills openvpn. The second part however does not seem to be executed.
I have the commands in my sudoers file in order to execute them from the script:
scripter ALL=(ALL) NOPASSWD: /usr/bin/killall openvpn, /usr/sbin/openvpn --config /etc/openvpn/nordVPN/nordRecent.ovpn.tcp --connect-retry 1i am clearly missing something small, but cannot see it. Does any of you lads see it? The lack of output makes troubleshooting REALLY hard ![]()
many thanks!
Last edited by BottleNeck (2021-02-19 18:44:57)
Offline
Killing openvpn cuts your ssh connection so you need to move away the script from the ssh shell so it doesn't die w/ the connection?
In that case, investigate on nohup, setsid and disown.
Online
apreaciate the input, i should have mentioned that they are in the same LAN. so i _think_ that cant be it.
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.7.0.1 128.0.0.0 UG 0 0 0 tun0
default 192.168.1.1 0.0.0.0 UG 202 0 0 eth0
default 10.7.0.1 0.0.0.0 UG 203 0 0 eth1
10.7.0.0 0.0.0.0 255.255.255.0 U 0 0 0 tun0
10.7.0.0 0.0.0.0 255.255.255.0 U 203 0 0 eth1
128.0.0.0 10.7.0.1 128.0.0.0 UG 0 0 0 tun0
link-local 0.0.0.0 255.255.0.0 U 207 0 0 docker0
link-local 0.0.0.0 255.255.0.0 U 272 0 0 vethd27f5a1
172.16.141.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 #LAN
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker_gwbridge
192.168.1.0 0.0.0.0 255.255.255.0 U 202 0 0 eth0
213.232.87.184 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0just to vertify:
#!/bin/bash
echo "Closing connection to OpenVPN "
sudo killall openvpn
sleep 2
echo "Connecting to OpenVPN "
cd /home/scripter
sudo /usr/sbin/openvpn --config "/etc/openvpn/nordVPN/nordRecent.ovpn.tcp" --connect-retry 1 &
echo "testing connection seth is awesome"from remote console:
ssh -i ~/.ssh/id_rsa_pi scripter@pi3
Closing connection to OpenVPN
Connecting to OpenVPN
testing connection seth is awesome
Connection to pi closed.Finally, as you can see on the console, the part where vpn should be starting gives nothing on output, is there a way to get that to remote console, so i can troubleshoot a bit? The output was on local console.
Last edited by BottleNeck (2021-02-19 14:28:55)
Offline
sudo /usr/sbin/openvpn --config "/etc/openvpn/VPN/Recent.ovpn.tcp" --connect-retry 1
…
scripter ALL=(ALL) NOPASSWD: /usr/bin/killall openvpn, /usr/sbin/openvpn --config /etc/openvpn/nordVPN/nordRecent.ovpn.tcp --connect-retry 1
…
sudo /usr/sbin/openvpn --config "/etc/openvpn/nordVPN/nordRecent.ovpn.tcp" --connect-retry 1 &
So the first command was vastly different from the sudoer one, the second looks close enough but has quotes.
You can use globbing, but it has to fit.
part where vpn should be starting gives nothing on output
Because it forks and the script terminates, closing the connection.
You still may have to
nohup sudo /usr/sbin/openvpn --config "/etc/openvpn/nordVPN/nordRecent.ovpn.tcp" --connect-retry 1 & disown %1 to prevent openvpn from dying on the SIGHUP
You still may have to nohup/disown
Online
It might be easier to make a systemd service, then the ssh command just needs to `systemctl restart whatever`.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Seth:
I am kind of at a loss with that suggestion
I tryed the nohup in my script, but than the script failed somehow... I'll read into it later, sounds usefull! However:
Trilby:
Great suggestion. I was working on a old debian machine that historically was using a /etc/init.d script. But after reading your post, it does seem horribly illogical to keep going the old way. So i made a systemd service, now everything works great! Thanks.
Offline