instructions

Although it is already early in the morning, I can not hide my excited mood. Today, I completed a big update to GotoSSH, adding two functional fat intestines, it is really easy to use, without further words, let’s look at the effect picture:

Normal one-click login:

Log in to the jumper with one click, and then jump to the online server:

One-click login to the jumper to view specified logs:

One-click login to the jumper to view the specified logs on the online server:

Then there is the more exciting content, one click from the jumper to copy specified files to the local:

One-click copy of a specified file from the production environment to the local directory:

All I can say is, it’s really strong.

A Shell script

The Shell script is available on Github at github.com/MFrank2016/…

Can go to download, easy to use, don’t forget to give a star.

Install dependencies

CentOS :

$ sudo yum install -y expect
Copy the code

Ubuntu :

$ sudo apt-get install tcl tk expect
Copy the code

Mac :

$ sudo brew install expect
Copy the code

Install GotoSSH

$ git clone https://github.com/MFrank2016/GotoSSH.git
$ cd GotoSSH
$ chmod a+x gotossh
$ sudo cp gotossh /usr/local/bin/
Copy the code

configuration

$ vim ~/.gotossh_config
server_name|ip|username|password|port|rely_server_no

[Server1]
commend=tail -f -n 10 testlog.log

[scp]
log1=~/testlog.log
Copy the code

The configuration file consists of three parts.

The first part is the basic information of the server.

server_name|ip|username|password|port|rely_server_no
Copy the code

Here’s an example:

22 JumpServer1 | 118.24.163.31 | root | testpassword | | 0 OnlineServerB | 111.231.59.85 | root | testpassword2 | | 1Copy the code

The last column indicates the server on which the server depends. If the value of this column is set to 0, it indicates that the server does not depend on other servers. Otherwise, you need to log in to other servers before logging in to the server.

The second part is custom commands, which you can set up individually for each server.

[Server1]
commend=tail -f -n 10 testlog.log
Copy the code

Server1 indicates the command set for the first server, and Server2 indicates the command set for the second server. There is no order requirement, just add this option for servers that need to set custom commands.

Commend is the name of the command, which can be used optionally, preferably simple and easy to type, with the equals sign followed by the actual command execution.

Here’s an example:

gotossh 1 commend
Copy the code

If you press Enter, the script will automatically log you to the first server and run tail -f -n 10 testlog.log.

Note that if you input command requires a password, need behind the command to bring the password, and use | space.

Here’s an example:

[Server1] commend = SCP [email protected]: / var /log/test-service/test-service.log ./test-server.log|testpassword2
Copy the code

Of course, it is strongly recommended not to put sensitive operations such as RM-RF XXX in this section, because if improperly configured, accidents may occur.

The last part of the configuration file is support for the SCP command.

[scp]
log1=~/testlog.log
log2=/var/log/test-service/test-service.log
Copy the code

Log1 and log2 are arbitrary names followed by the path to the file you want to copy from the server. Once configured, you can use these names:

gotossh 1 scp log1
Copy the code

It will automatically copy the ~/testlog.log file from the first server to your local computer.

gotossh 2 scp log2
Copy the code

This operation is more severe, because the second server set the dependence on the first server, so it will log on to the first server first, and then copy the file on the second server to the first server, and finally, withdrew from the server to the local, will be the first server on the copy to the local copy.

Configuration File Examples

$vim ~ /. Gotossh_config JumpServer1 | 118.24.163.31 | root | testpassword | | 0 22 OnlineServerB | 111.231.59.85 | root | testpassword2 | | 1 (Server1)log=tail -f -n 20 testlog.log

[Server2]
log=tail -f -n 20 /var/log/test-service/test-service.log
cd=cd /var/log/test-service/

[scp]
log3=~/testlog.log
log4=/var/log/test-service/test-service.log
Copy the code

usage

$ gotossh
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# [GOTO SSH] #
# #
# #
# [1] test_server-192.168.0.1 :root #
# [2] online_server-192.168.2.2 :root #
# #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Server Number:(Input Server Number Here)
Copy the code
gotossh 1
gotossh 2
gotossh 1 log
gotossh 2 log
gotossh 2 cd
gotossh 1 scp log3
gotossh 2 scp log4
Copy the code

What problem was solved

  1. To query online server logs, you need to log in to the jumper first and then to the server, which is cumbersome. You need to view server information several times, such as IP address, user name, and password, and then copy the information back and forth. Using GotoSSH, after configuring the server information, you can directly jump to one key.
  2. Added the custom command after logging in to the server, which is mainly used to view the log path of the service, and then cut back to view the log. Since the operation is a template each time, why not simplify it?
  3. Sometimes the operation on the server is very inconvenient, because of the strict restrictions on permissions, many commands can not be used, so the pair is addedscpCommand support, you can copy online server logs to the local one key, is not delectable.

Finally, please attach the project address: github.com/MFrank2016/…

If you feel good, don’t forget to add a star✨ also welcome to follow my public account message exchange.