SkillAgentSearch skills...

GotoSSH

Automatic login SSH (一键登录SSH,可直接从跳板机登录到线上服务器)

Install / Use

/learn @MFrank2016/GotoSSH
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

GotoSSH

<a name="english"></a>

Description

GotoSSH is committed to helping you improve work efficiency.

There are some pics, they will show you to what this shell can do.

Normal login with no subsequent operation:

Login the jump server first, and then jump to the online server:

Login the server and view the log:

Login the jump server and then login the online sever to view the log:

Copy file from the remote server:

Copy file from the online server:

List all the servers:

List all the custum commands and common commands the server supported:

list-all-the-commands.gif

Dependencies

CentOS :

$ sudo yum install -y expect

Ubuntu :

$ sudo apt-get install tcl tk expect

Mac :

$ brew install expect
$ brew install gnu-sed --with-default-names
$ export PATH="$(brew --prefix coreutils)/libexec/gnubin:/usr/local/bin:$PATH"
$ export MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"

Install GotoSSH

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

If you have installed the older version, you need to remove it in /usr/local/bin/.

Config

$ vim ~/.gotossh_config
JumpServer||111.231.59.85||root||password||22||0
JumpServer2||111.231.59.85||root||password||22||0
OnlineServer||118.24.163.31||root||password||22||1


[Server-JumpServer]
distributor-log=tail -f -n 500 /var/log/[service-name]/[service-name].log
cd=cd /var/log/[service-name]/
cd1=cd [P1][P2]

[Server-Attribute-JumpServer]
service-name=test-service

[Server-OnlineServer]

[Server-Attribute-OnlineServer]
service-name=online-service

[scp]
log1=~/testfile2
log2=/var/log/omp-distribution-facade-service/omp-distribution-facade-service.log
log3=~/testlog.log
log4=/var/log/test-service/test-service.log
log5=/logs/openapi/service/omp-distributor-service.log
bill-log=/var/log/omp-bill-service/omp-bill-service.log


[settings]
version=3.0

[common-command]
log=tail -f -n 500 /var/log/[service-name]/[service-name].log
error-log=tail -f -n 500 /var/log/[service-name]/[service-name]-error.log

The config file consists of four parts.

server base info

The first part is the server base info:

link_name||ip||username||password||port||rely_server_no||service_name

For example:

JumpServer||111.231.59.85||root||password||22||0||test-service

The rely_server_no column means this server relies another server, so this shell script will login that server first.(the rely_server_no starts form 1, so 0 means this server doesn’t rely any other server)

server custom info

The second part is custom commands and custom attributes, you could set any command here for each server.

[Server-link_name]
command=xxxxxx

[Server-Attribute-link_name]
attribute=xxx

Server-link_name means it's set for the server who has the link-name of link_name.

command is the name of your command, that could be any name you like, and the actual command is behind the equals sign.

The part of Server-Attribute-link_name is setted for custom command and common command, when you use custom attribute in command like this /var/log/[service-name]/[service-name].log, this script will find this attribute in the node of Server-Attribute-link_name.

For example:

[Server-JumpServer]
distributor-log=tail -f -n 500 /var/log/[service-name]/[service-name].log
cd=cd /var/log/[service-name]/
cd1=cd [P1][P2]

[Server-Attribute-JumpServer]
service-name=test-service

As you can see, there are two special attibutes:[P1] [P2] that means the params you send to this script.

So you could use it by this way:

gotossh  1  cd1  /var  /log

The final command will be : cd /var/log.

And it will login the first server and excute this command cd /var/log.

Notice that, if your command needs a password, like 'scp root@xxxx:xxx xxx', you should add the pwd after the command.

For example:

[Server1]
command=scp root@111.231.59.85:/var/log/test-service/test-service.log ./test-server.log|testpassword2

scp command

The next part is the support of scp command:

[scp]
log1=~/testfile2
log2=/var/log/omp-distribution-facade-service/omp-distribution-facade-service.log
log3=~/testlog.log
log4=/var/log/test-service/test-service.log
log5=/logs/openapi/service/omp-distributor-service.log
bill-log=/var/log/omp-bill-service/omp-bill-service.log

log1 and log2 are the name you set, and the actual path of the file in server is behind the equals sign.

You could use it like this:

gotossh 1 scp log1

It will copy the remote file on the first server to your local computer.

gotossh 3 scp log2

It will login the first server, and copy that file from the third server, and then copy that file to your local computer.

And you can also use it like this:

gotossh 3 scp /var/log/online-service/online-service.log

This script will find the log name of /var/log/online-service/online-service.log in the scp node, if it cann't find the log name, the script will treat it as the file path.

settings and common command

The last part of the config file is settings and common command, in settings node, there is only the version info now. Maybe we could change many other things ,like color etc, here.

common command is a global setting for all servers, you can treat it as template command, there will appear in all servers's COMMAND LIST. And you could use custom attribute here.

For example:

[settings]
version=3.0

[common-command]
log=tail -f -n 500 /var/log/[service-name]/[service-name].log
error-log=tail -f -n 500 /var/log/[service-name]/[service-name]-error.log

Useage

$  gotossh
#############################################################################
#                                [GOTO SSH]                                 #
#                                                                           #
#                                                                           #
# [1] JumpServer                                                            #
# [2] JumpServer2                                                           #
# [3] OnlineServer                                                          #
#                                                                           #
#############################################################################
Server Number:1
#############################################################################
#                              [COMMAND LIST]                               #
#                                                                           #
# [1] no-subsequent-operation                                               #
# [2] distributor-log                                                       #
# [3] cd                                                                    #
# [4] cd1                                                                   #
# [5] log                                                                   #
# [6] error-log                                                             #
#                                                                           #
#                                                                           #
#############################################################################
Command Number:1

You could select the server you want to login in the first step. And then you will see all the

$ gotossh 1
#############################################################################
#                              [COMMAND LIST]                               #
#                                                                           #
# [1] no-subsequent-operation                                               #
# [2] distributor-log                                                       #
# [3] cd                                                                    #
# [4] cd1                                                                   #
# [5] log                                                                   #
# [6] error-log                                                             #
#                                                                           #
#                                                                           #
#############################################################################
Command Number:1
gotossh 2
gotossh 1 log
gotossh 2 log
gotossh 2 cd
gotossh 1 scp log3
gotossh 3 scp /var/log/online-service/online-service.log

<a name="chinese"></a>

说明

GotoSSH 是一个一键登录 SSH 的脚本,可直接从跳板机登录到线上服务器,致力于帮助你提高工作效率。

这里有一些动态图,可以帮助你快速了解这个脚本能够做什么。

普通的一键登录到服务器:

先登录跳板机,然后自动跳转到线上服务器:

登录服务并查看日志:

登录跳板机,然后跳转线上服务器并查看指定日志:

从服务器复制文件到本地:

从线上服务器复制文件到跳板机,然后再复制到本地:

列举所有服务器:

![](https://i.loli.ne

Related Skills

View on GitHub
GitHub Stars131
CategoryDevelopment
Updated1mo ago
Forks41

Languages

Shell

Security Score

80/100

Audited on Mar 7, 2026

No findings