-1

I'm running debian (latest version i believe), and I just can not get my script to run at boot. I've enabled it with update-rc.d, and tried saving it to /etc/network/if-up.d but it just won't start. When I run it manually it works fine. Can anyone please point me in the right direction?

Znerox
  • 1
  • 1
  • what does the script do, does it need to run as a user? post the script. – Jacob Evans Nov 07 '15 at 03:19
  • It sets up a reverse ssh tunnel to another debian machine. #!/bin/sh ### BEGIN INIT INFO # Provides: sshtunnel # Required-Start: $local_fs $network # Required-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: # Description: sshtunnel ### END INIT INFO autossh -R 200:localhost:22 [2 more port forwards] autossh@example.com -p 22 – Znerox Nov 07 '15 at 09:42

2 Answers2

0

Easy Answer, call it in /etc/rc.local before exit 0

or

crontab -e

@reboot script

Also try a keepalive script like this:

#!/bin/bash
nc -z -w5 IP PORT
if [ $? -eq 1 ]; then
screen -dmS SSHTunnel autosshcommand
else
exit 0;
fi
Jacob Evans
  • 7,636
  • 3
  • 25
  • 55
  • Already tried rc.local, doesn't work – Znerox Nov 06 '15 at 23:40
  • ls -lah results? chmod a+x script and place script in /usr/local/sbin/ – Jacob Evans Nov 07 '15 at 03:18
  • Tried adding it to crontab (with script placed at file system root). When checking the machine the script is supposed to ssh into, "last" outputs this: "autossh pts/0 [my ip] Sat Nov 7 10:50 - 10:50 (00:00)" So it seems the script is running, but the tunnel is not staying open. This seem to have happend a number of times last night too, when I was trying to run the script from init.d. Which logs should I check to find any errors, except /var/log/daemon.log? – Znerox Nov 07 '15 at 09:56
  • Launch it into screen or background the process – Jacob Evans Nov 07 '15 at 12:51
0

Finally got this working. I had to add the -N argument to the ssh command, and made it run @reboot with crontab like Jacob Evans suggested. Even now that it's working, the login doesn't show in "last" on the receiving end of the ssh tunnel. I had this exact same script without the -N argument working on an older install, and with that setup I could use "last" to see whether it is connected or not. But the important thing is it's working now.

Znerox
  • 1
  • 1