LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-25-2019, 11:00 PM   #1
Subito Piano
LQ Newbie
 
Registered: Nov 2007
Location: UPSTATE New York
Distribution: Puppy; A/V Linux for playing live synth
Posts: 23

Rep: Reputation: 0
Bash script -- how to connect to vpn


Hi! I am trying to write a bash script as such:
Code:
#!/bin/bash
sleep 30
modprobe ipv6
modprobe tun
pvpn -l servername tcp
The 3 commands work fine in a terminal, but the third one does not execute in my script. (This script is in my startup folder; the delay is necessary to allow time for my laptop to connect to the 'net.)

I also tried
Code:
#!/bin/bash
sleep 30
modprobe ipv6 && modprobe tun && pvpn -l 162 tcp
-- to no avail. Any ideas where my error lies? Thanks!
 
Old 06-25-2019, 11:09 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

what do you mean by "does not execute"? Have you tried putting in some simple echo statements to try to dbug it. Eg
Code:
#!/bin/bash
echo "Will sleep for 30 seconds..."
sleep 30
echo "inserting ipv6 module"
modprobe ipv6
echo "inserting tun module"
modprobe tun
echo "Will run pvpn from"
which pvpn
pvpn -l servername tcp
echo "pvpn exited with code $?"
Evo2.
 
Old 06-25-2019, 11:23 PM   #3
Subito Piano
LQ Newbie
 
Registered: Nov 2007
Location: UPSTATE New York
Distribution: Puppy; A/V Linux for playing live synth
Posts: 23

Original Poster
Rep: Reputation: 0
Thanks Evo --
Just for the record, were i to call myself a Bash neophyte, i'd be bragging.
I copied your suggested script into the file in place of what i had -- nothing printed.
What i mean by "does not execute" is that i checked my IP address and it had not changed. I entered that last command to start the vpn service and it connected without complaining that my ipv6 service hadn't started like it would had i just booted up. So i know that the first two commands are carried out but not the third.
It's getting really late here on the east coast (US) and i'm seriously shorting myself of needed sleep, so I'll be offline until after work tomorrow. Thanks.

Last edited by Subito Piano; 06-25-2019 at 11:37 PM.
 
Old 06-25-2019, 11:39 PM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

Quote:
Originally Posted by Subito Piano View Post
Just for the record, were i to call myself a Bash neophyte, i'd be bragging.
I copied your suggested script into the file in place of what i had -- nothing printed.
Did you actually run the script? If so, how?

Quote:
Originally Posted by Subito Piano View Post
What i mean by "does not execute" is that i checked my IP address and it had not changed. I entered that last command to start the vpn service and it connected without complaining that my ipv6 service hadn't started like it would had i just booted up. So i know that the first two commands are carried out but not the third.
It's getting really late here on the east coast (US) and i'm seriously shorting myself of needed sleep, so I'll be offline until after work tomorrow.
I think you need to try running the script from the terminal and look at the output.

Evo2.
 
Old 06-26-2019, 02:11 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Code:
#!/bin/bash
set -xv
sleep 30
modprobe ipv6
modprobe tun
pvpn -l servername tcp
Now run the script and show us ALL its output.
BTW, I'm pretty sure you're supposed to substitute something for "servername".
 
1 members found this post helpful.
Old 06-26-2019, 03:14 PM   #6
Subito Piano
LQ Newbie
 
Registered: Nov 2007
Location: UPSTATE New York
Distribution: Puppy; A/V Linux for playing live synth
Posts: 23

Original Poster
Rep: Reputation: 0
Thanks, ondoho --
Yeah, "servername" was just my substitute for the actual servername. My syntax was incorrect, i only needed "pvnp -l" to connect to the previously-chosen server, but that's not my problem anyway.
I ran your script -- no output. That's the thing. I can run the commands in terminal -- no problem. I can reboot and click on the script, and it executes. However, when i place the script in my startup folder, it does not automatically execute. I can place it in /usr/bin and symlink it (which i've never had to do anyway) -- and still no go upon reboot. So the real issue is why this particular script won't autostart -- just that last line telling it to connect. The first two lines definitly kick in. I have several custom scripts in that folder or symlinked to it, and i've never run into this issue before, not even when there is a sleep command upfront.

Running xenialpup linux on a sturdy old Lenovo/IBM T60. (And yes, it is stamped with BOTH manufacturer's names!)

Last edited by Subito Piano; 06-26-2019 at 03:34 PM.
 
Old 06-26-2019, 07:10 PM   #7
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,
Quote:
Originally Posted by Subito Piano View Post
Thanks, ondoho --
Yeah, "servername" was just my substitute for the actual servername. My syntax was incorrect, i only needed "pvnp -l" to connect to the previously-chosen server, but that's not my problem anyway.
I ran your script -- no output.
Really? You ran a script that has echo statements, and there was no output? Exactly what did you do to run it?
Quote:
Originally Posted by Subito Piano View Post
That's the thing. I can run the commands in terminal -- no problem. I can reboot and click on the script, and it executes. However, when i place the script in my startup folder, it does not automatically execute. I can place it in /usr/bin and symlink it (which i've never had to do anyway) -- and still no go upon reboot. So the real issue is why this particular script won't autostart -- just that last line telling it to connect. The first two lines definitly kick in. I have several custom scripts in that folder or symlinked to it, and i've never run into this issue before, not even when there is a sleep command upfront.

Running xenialpup linux on a sturdy old Lenovo/IBM T60. (And yes, it is stamped with BOTH manufacturer's names!)
What is "my startup folder"? Why are you expecting this script to be run automatically when your machine boots?

Evo2.
 
Old 06-26-2019, 07:48 PM   #8
Subito Piano
LQ Newbie
 
Registered: Nov 2007
Location: UPSTATE New York
Distribution: Puppy; A/V Linux for playing live synth
Posts: 23

Original Poster
Rep: Reputation: 0
Oops! Silly me -- i copied and pasted everything including the shebang.
OK -- here is the output:
Code:
sh-4.3# sleep 30
sleep 30
+ sleep 30
sh-4.3# modprobe ipv6
modprobe ipv6
+ modprobe ipv6
sh-4.3# modprobe tun
modprobe tun
+ modprobe tun
sh-4.3# pvpn -l servername tcp
It's stuck on the last line and does not execute it, i would need to manually hit ENTER.
Now, startup folders are a convenience for Puppy users. Anything we stick in there or link to it gets executed on startup....but not this script. Weird.
 
Old 06-26-2019, 07:52 PM   #9
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,738

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
You ran a script with set -xv and there was no output? In the terminal?
That makes no sense...

I’m wondering if there’s an issue with the script finding the commands?
Try using the absolute paths to each command.

Edit: Make sure there’s a return at the end of the last line...

Last edited by scasey; 06-26-2019 at 07:53 PM.
 
Old 06-27-2019, 01:05 AM   #10
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by Subito Piano View Post
Oops! Silly me -- i copied and pasted everything including the shebang.
OK -- here is the output:
Code:
sh-4.3# sleep 30
sleep 30
+ sleep 30
sh-4.3# modprobe ipv6
modprobe ipv6
+ modprobe ipv6
sh-4.3# modprobe tun
modprobe tun
+ modprobe tun
sh-4.3# pvpn -l servername tcp
It's stuck on the last line and does not execute it, i would need to manually hit ENTER.
Now, startup folders are a convenience for Puppy users. Anything we stick in there or link to it gets executed on startup....but not this script. Weird.
It seems you do not understand what a script is.
Please do the following:
Copy the code from post #5 and paste it into a text editor window.
Then save the whole thing in a suitable folder (can be your home folder) under the name myvpn.sh
Now open a terminal in that folder, maximise it, and issue the following commands, one after the other, pressing <Enter> after each command:
Code:
chmod +x ./myvpn.sh
./myvpn.sh
Then show us the complete terminal output.
 
Old 06-27-2019, 01:33 PM   #11
Subito Piano
LQ Newbie
 
Registered: Nov 2007
Location: UPSTATE New York
Distribution: Puppy; A/V Linux for playing live synth
Posts: 23

Original Poster
Rep: Reputation: 0
Thanks for the clear instructions, ondoho. Like i said, i'm definitely entry-level, but i did understand what you had me do -- except for looking up the "set" command and parameters. I've never had to use the sh extension to get a script running, though -- i just changed permissions and clicked on it and all was fine. Anyway, here is the output, after i changed the third line in my script to put in the absolute path and have it connect me to a particular server:
Code:
sh-4.3# ./myvpn.sh
sleep 30
+ sleep 30
modprobe ipv6
+ modprobe ipv6
modprobe tun
+ modprobe tun
/usr/local/bin/protonvpn-cli -c US-NY#X tcp
+ /usr/local/bin/protonvpn-cli -c US-NY#X tcp
Fetching ProtonVPN servers...
Connecting...
[!] Error connecting to VPN.
sh-4.3#
Opening a terminal after the above error, i can now re-run the last line of my script and get success:
Code:
sh-4.3# pvpn -c US-NY#X tcp
Fetching ProtonVPN servers...
Connecting...
[$] Connected!
[#] New IP:  XXX.XX.XX.XXX
 sh-4.3# 
(Of course, i swapped out the numbers above for Xs.)

So --for some reason it fails to connect in the script.

Thanks for hanging with me.

Last edited by Subito Piano; 06-27-2019 at 01:36 PM.
 
Old 06-27-2019, 04:03 PM   #12
Subito Piano
LQ Newbie
 
Registered: Nov 2007
Location: UPSTATE New York
Distribution: Puppy; A/V Linux for playing live synth
Posts: 23

Original Poster
Rep: Reputation: 0
I altered the script to read
Code:
#!/bin/bash
sleep 25
modprobe 1pv6
modprobe tun
roxterm /usr/local/bin/protonvpn-cli -c US-NY#X tcp
and received the message from roxterm:
Code:
Error parsing command line options: Error parsing option -c
So -- is it the options after the command that cause this script to fail? It DOES work when entered in a terminal.

Curiously, if I click on that script a second time, it works...!?!?

Last edited by Subito Piano; 06-27-2019 at 04:15 PM.
 
Old 06-28-2019, 02:18 AM   #13
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
/usr/local/bin/protonvpn-cli and pvpn are two different commands. how on earth could their behaviour be the same?
anyhow, try to put US-NY#X in double quotes: "US-NY#X" or maybe even "US-NY#X tcp".
 
Old 06-29-2019, 08:09 AM   #14
Subito Piano
LQ Newbie
 
Registered: Nov 2007
Location: UPSTATE New York
Distribution: Puppy; A/V Linux for playing live synth
Posts: 23

Original Poster
Rep: Reputation: 0
Ah, my mistake -- i should have explained that "pvpn" is just a shortcut to protonvpn-cli. That shortcut came with the program; must be Proton figures that users would rather type 4 letters instead of 13....

Anyway, no go on the quotes. This has become one of those issues that i'm only hanging on to b/c i don't like not understanding things or admitting defeat. However, it's taking way too much of both my time and yours. I can just leave the shortcut on my desktop and click it after the desktop loads.

You've been most helpful -- THANK YOU!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Windows7 VPN clients behind Debian Gateway can not connect to Draytek VPN neopandid Linux - Server 3 08-31-2012 11:34 PM
New to VPN, want to use firefox after vpn connect DropSig Linux - Networking 2 05-16-2008 03:23 PM
Linux VPN Software - How to Connect to a Windows VPN wfernley Linux - Software 2 02-07-2006 09:40 AM
How do i connect Ciscos VPN client to Checkpoint VPN server Klas Linux - Networking 1 11-29-2003 08:00 AM
Connect to Cisco VPN w/o Cisco VPN Client gboutwel Linux - Networking 4 02-07-2003 12:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration