0

For a reason sudo pkill $(jobs -p 1) can't kill the process but sudo pkill works outside the script

#!/bin/bash
pipe=/tmp/outpipe_vpn
mkfifo $pipe

##random command to enter sudo password
sudo echo

sudo /home/utku3/Programlar/namespaced-openvpn-master/namespaced-openvpn --config '/home/utku3/vpn/FreeVPN.me-OpenVPN-Bundle-July-2020/FreeVPN.me - Server1-NL/Server1-TCP443.ovpn' >$pipe & grep -m1 "Initialization Sequence Completed" $pipe && (xhost local: ; sudo ip netns exec protected sudo -u vpn sh -c "DISPLAY=:0 firefox --private-window")
## I exit firefox

jobs
jobs -p 1
## it fails to kill the process
sudo kill $(jobs -p 1)

sleep 5

jobs
jobs -p 1
##and fails again
sudo kill $(jobs -p 1)

jobs
jobs -p 1

rm $pipe

and output:

utku3@utku3:~/Programlar$ /home/utku3/Programlar/vpn

Sun Jan 17 23:42:56 2021 Initialization Sequence Completed
non-network local connections being added to access control list
[1]+  Running                 sudo /home/utku3/Programlar/namespaced-openvpn-master/namespaced-openvpn --config '/home/utku3/vpn/FreeVPN.me-OpenVPN-Bundle-July-2020/FreeVPN.me - Server1-NL/Server1-TCP443.ovpn' > $pipe &
7838
[1]+  Running                 sudo /home/utku3/Programlar/namespaced-openvpn-master/namespaced-openvpn --config '/home/utku3/vpn/FreeVPN.me-OpenVPN-Bundle-July-2020/FreeVPN.me - Server1-NL/Server1-TCP443.ovpn' > $pipe &
7838
[1]+  Running                 sudo /home/utku3/Programlar/namespaced-openvpn-master/namespaced-openvpn --config '/home/utku3/vpn/FreeVPN.me-OpenVPN-Bundle-July-2020/FreeVPN.me - Server1-NL/Server1-TCP443.ovpn' > $pipe &
7838
utku3@utku3:~/Programlar$ sudo kill 7838

openvpn process only quits after I run sudo kill 7838 manually

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.