Email: bknpk@hotmail.com Phone: +972-54-7649119
V

 

debian script, which runs at system startup, to open a tunnel via ssh.

  1. The script is used to connect my daughter's debian VM ware machine to mine. In order to save clicking on an icon, I created a script, which runs at startup, and fires up the ssh tunnel.
    This page will describe all the needed steps, from writing the script, setting run levels, add it to the initialization flow.

  2. The work is done by two scripts. After writing the script, I checked it via:
    ./my_script.unx start
    ./my_script.unx stop
    Although it worked well from prompt using super user, it did not fired the ssh in the boot process. The reason was, that I probably did not specify the dependencies correctly. This is done in the field in the header of the script. Since I tired to have it run last ($ALL) and it did not work, I used another script. Its first line is a delay (not too good practice). The second script is put in background and also used with no hang up command.

  3. The script was stored in /etc/init.d/. Then I added the script:
    insserv my_script.unx
    I installed rcconf to check, that the script was placed correctly (it can be also checked with a simple command:
    ls ../rc2.d/)

  4. In the start section I call to the second script:
    #su - pini -c "nohup ssh -f -N -R 2230:localhost:22 guestA@192.168.2.106"
    nohup /etc/init.d/my_script_st.unx &
    The script, my_script_st.unx, does the same, with delay:
    sleep 60
    date >> /var/log/pini_my_script.txt
    su - pini -c "nohup ssh -f -N -R 2230:localhost:22 guestA@192.168.2.106"

  5. The stop part checks if the process exists, if so gets its process ID and kills it.
    var=`ps -aefH | grep "ssh .*2230:localhost" | grep -v grep`
    pid=`echo $var | sed 's/pini \([0-9]*\) \([0-9]*\).*/\1/'`
    kill $pid

  6. The scripts can be downloaded from:
    ssh tunnel from boot .


Contact me now at:

  ...


I would be happy to offer my services. Call ASAP !


Home

Download Area






Search This Site


Feedback This Site




new pages on this site