Linux - NewbieThis 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.
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.
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
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)
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.