Expose the port of the ssh tunnel to another machine and automatically detect the script.

Source: Internet
Author: User
Expose the ssh tunnel port to another machine and automatically detect the script Java code #! /Bin/bashPIDS 'PS-ef | grepssh | grep9222 | awk & amp; #39; {print $2} & amp; #39; 'if [-z & quot; $ PIDS & quot;]; then # check whether the service has opened the ss ssh tunnel to expose the port to another machine and automatically detect the script Java code #! /Bin/bash PIDS = 'PS-ef | grep ssh | grep 9222 | awk '{print $2} ''if [-z" $ PIDS "]; then # check whether the service has enabled ssh-C-f-N-g-R 9222: 127.0.0.1: 22 root@42.121.119.100 echo "start ssh exporter: 'date' ">/home/deploy/autocheck/log.txt else nc-w 3-z 42.121.119.100 9222>/dev/null 2> & 1 if [$? -Ne 0]; then # check whether the port is connected to kill-9 $ PIDS ssh-C-f-N-g-R 9222: 127.0.0.1: 22 root@42.121.119.100 echo "kill and start ssh exporter: 'date'">/home/deploy/autocheck/log.txt fi because the ssh tunnel is sometimes automatically disabled, therefore, you need to add crontab to check the Java code every minute */1 *****/home/deploy/autocheck/e. sh this script exposes the port 22 of the local machine to 9222 of port 42.121.119.100, so that the local machine can be connected through ssh 42.121.119.100-p 9222. Another step is to enable password-free login from the local machine to 42.121.119.100.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.