Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
06-09-2017, 06:11 AM
|
#1
|
Member
Registered: Aug 2012
Posts: 789
Rep: 
|
Adding script to rc.local
How come I can execute /usr/local/bin/mytunnel.sh (script shown below) directly from the cli and it will spawn a ssh socket process, yet adding /usr/local/bin/tempaccess.sh to /etc/rc.local will not?
Code:
#!/bin/sh
ip=12.34.567.89
while [ true ] ;
do
if [ $(ss dst $ip | grep -q '$ip:ssh') ]
then
sleep 4
else
#Note that following is a blocking command given server configuration
ssh -R 2220:localhost:22 myuser@$ip
fi
done
|
|
|
06-09-2017, 06:19 AM
|
#2
|
LQ Guru
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 6,358
|
Quote:
Originally Posted by NotionCommotion
How come I can execute /usr/local/bin/mytunnel.sh (script shown below) directly from the cli and it will spawn a ssh socket process, yet adding /usr/local/bin/tempaccess.sh to /etc/rc.local will not?
Code:
#!/bin/sh
ip=12.34.567.89
while [ true ] ;
do
if [ $(ss dst $ip | grep -q '$ip:ssh') ]
then
sleep 4
else
#Note that following is a blocking command given server configuration
ssh -R 2220:localhost:22 myuser@$ip
fi
done
|
There could be many possible reasons, but for one you have set no path. Since anything run from the rc.local runs as root but before any logon, the path is not set. You must either call each external executable using the full path name or set a path variable that contains all of the paths to the different executables you will call.
For another, the rc.local is NOT executable by default on most modern distributions. If you are going to modify it to call another script, make sure that both scripts are executable. (permission 755 will do, or 500 if you want it to be secure, I use 750 on mine for convenience)
|
|
|
06-09-2017, 09:05 AM
|
#3
|
Member
Registered: Aug 2012
Posts: 789
Original Poster
Rep: 
|
Thanks wpeckham,
Yeah, multiple reasons!
Not path as they were being resolved.
Didn't have pki keys for root, only my normal user.
|
|
|
06-09-2017, 09:49 AM
|
#4
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
If you want it to reconnect automatically you can put the SSH client itself inside a loop:
Code:
while ! ssh -o ServerAliveInterval=20 -i ./some.key.rsa -R 2220:localhost:22 myuser@$ip; do sleep 2; done;
Also, pretty much all of those options could be stored in ~/.ssh/config to make it shorter. Put it in at the top of the configuration file.
Code:
Host myshortcut
HostName 203.0.113.111
User myuser
IdentityFile /home/me/some.key.rsa
ServerAliveInterval 20
RemoteForward localhost:2220 localhost:22
So to use that, it'd be the following:
Code:
while ! ssh myshortcut; do sleep 2; done;
See "man ssh_config" for all the options.
|
|
2 members found this post helpful.
|
06-10-2017, 08:32 PM
|
#5
|
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908
|
Quote:
Originally Posted by NotionCommotion
How come I can execute /usr/local/bin/mytunnel.sh (script shown below) directly from the cli and it will spawn a ssh socket process, yet adding /usr/local/bin/tempaccess.sh to /etc/rc.local will not?
Code:
#!/bin/sh
ip=12.34.567.89
while [ true ] ;
do
if [ $(ss dst $ip | grep -q '$ip:ssh') ]
then
sleep 4
else
#Note that following is a blocking command given server configuration
ssh -R 2220:localhost:22 myuser@$ip
fi
done
|
If your distribution is using systemd, verify that "NetworkManager-wait-online" is enabled.
One way for the failure to occur is that the network is not yet ready when rc.local is run.
|
|
|
06-11-2017, 07:45 AM
|
#6
|
LQ Guru
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 6,358
|
Another good idea is to trap and redirect the STDOUT and STDERR to a couple of files so you can READ them and see what messages they log.
That might look something like
Code:
/usr/local/bin/mytunnel.sh >/tmp/mytun.out 2>/tmp/mytun.err
|
|
|
06-11-2017, 08:00 AM
|
#7
|
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908
|
Systemd is SUPPOSED to catch all the error messages and log them.
:-)
|
|
|
All times are GMT -5. The time now is 12:07 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|