C
C
Coloritt2017-02-22 17:03:36
linux
Coloritt, 2017-02-22 17:03:36

How to add .sh script to Debian 8 startup?

Hello! You need to run a .sh script at system startup that will connect to the ssh server (raise the ssh tunnel).
The config for the connection is in the file /home/user/connect.sh I added a line to /etc/rc.local
/home/user/connect.sh
But it stubbornly refuses to connect, please tell me how and where to register correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Chudnovsky, 2017-02-22
@Frankenstine

Running from /etc/rc.local is an unpredictable thing, because, for example, the launch may occur before the network is up, and therefore the script will break off.
In a good way, you need to take some network service (for example, Apache, if installed) from /etc/init.d as a sample, and create your own scripts by setting them to run under a number (for sysv init), greater than those services that are needed already running when your service starts (or, for systemd, by writing the correct dependencies).
At worst, the script can be run from the crontab of the desired user by inserting the line:
but the script will not work out the shutdown of the system, so it's better to take care of creating a normal service.

M
myppomeu, 2017-03-05
@myppomeu

I suggest using systemd. Create a view file /etc/systemd/system/ssh_tunnel.service
Sample contents:

[Unit]
Description=SSH tunnel
After=syslog.target network.target

[Service]
Type=forking

User=user
ExecStart=/usr/bin/ssh -i /home/user/.ssh/key -N -T -L 127.0.0.1:51143:192.168.5.5:143 -o [email protected] [email protected]
ExecStop=/bin/kill $MAINPID
ExecReload=/bin/kill $MAINPID && /usr/bin/ssh -i /home/user/.ssh/key -N -T -L 127.0.0.1:51143:192.168.5.5:143 -o [email protected] [email protected]
Restart=on-failure

[Install]
WantedBy=multi-user.target

Update systemd information:
Start the service:
Check its status:
If everything is in order, include it in autoload:
systemctl enable ssh_tunnel.service

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question