I wrote the following command in /etc/rc.local
:
ssh -R 32400:192.168.0.100:32400 root@marcin.com -N
but it won't start.
Any idea why?
I wrote the following command in /etc/rc.local
:
ssh -R 32400:192.168.0.100:32400 root@marcin.com -N
but it won't start.
Any idea why?
Maybe the network isn't ready yet, when rc.local
is executed.
The following code will wait for the network before connecting:
(
until ping -nq -c3 W.X.Y.Z; do
# Waiting for network
sleep 5
done
ssh -R 32400:192.168.0.100:32400 root@marcin.com -N
)&
W.X.Y.Z
is an IP address that is reachable and replies to pings. It maybe be the default gateway of your network, the Google DNS (8.8.8.8), etc.
Code between parenthesis runs in a new shell, and the &
makes it run in background. It won't block the execution of rc.local
.
The commands between until
and done
will be repeated until the ping
is successful, i.e., it gets a reply (i.e., the network is up).
rc.local
was placed in /etc
for me. I also had to ensure it was executable (sudo chmod 775 /etc/rc.local
) and place #!/bin/sh -e
at the top: https://askubuntu.com/questions/9853/how-can-i-make-rc-local-run-on-startup/401090#401090
– SharpC
Feb 08 '20 at 13:17
/etc/rc.local
as they don't run in a terminal. I guess you want to run this in a terminal / tty once logged in right? Do you login using a GUI or using a tty? – kos Sep 10 '15 at 17:05