代码拉取完成,页面将自动刷新
linux服务器批量操作工具。
提供三个功能:
通过组合这三个功能能完成大多数Linux服务器上的操作。
config.yaml文件
port: 22
root-prompt: '#'
passwd-prompt: '.*assword.*'
timeout: 10
user: 'kehao'
passwd: '123456'
root-passwd: '123456'
hosts:
- '172.18.0.3'
- '172.18.0.4'
spc-hosts:
- '127.0.0.1 23 123456 123456'
IP PORT 用户密码 root用户密码
。command.yaml文件
put:
- /home/kehao/test1.sh#/home/kehao
exec:
- /bin/sh /home/kehao/test1.sh
get:
- /home/kehao/result1.txt#/home/kehao/result
install-arthas:
put:
- /home/kehao/arthas-xxx.zip#/home/kehao
- /home/kehao/install_arthas.sh#/home/kehao
- /home/kehao/jdk-xxx.zip#/home/kehao
- /home/kehao/install_jdk.sh#/home/kehao
exec:
- /bin/sh /home/kehao/install_arthas.sh
- /bin/sh /home/kehao/install_jdk.sh
get:
- /home/kehao/install_arthas_result.txt#/home/kehao/result
- /home/kehao/install_jdk8_result.txt#/home/kehao/result
本地文件路径#远程目录名称
,远程目录名称可缺省,默认与本地文件路径的目录名相同,ssh登录用户需要具有远程目录的写权限;root
用户执行;远程文件路径#本地目录名称
,本地目录名称可缺省,默认与远程文件路径的目录名相同,ssh登录用户需要具有远程文件的读权限;remote put [flags] [section]
remote exec [flags] [section]
remote get [flags] [section]
对config.yaml文件中的密码字段经行加密存储。
remote enc [flags]
remote --help
shell batch execute tool
Usage:
remote [command] [flags] [section]
Available Commands:
completion Generate the autocompletion script for the specified shell
enc encrypt config file
exec execute command on remote
get get file from remote
help Help about any command
put put file to remote
Flags:
-c, --command string Specify commands configuration (default "command.yaml")
-f, --config string Specify servers configuration (default "config.yaml")
-h, --help help for remote
-m, --netmask string ip filter, e.g. 192.168.1.1 192.168.1.1,192.168.1.2 192.168.0.0/24
-t, --thread int maximum number of concurrent (0 < t <= 16) (default 1)
-v, --version version for remote
Use "remote [command] --help" for more information about a command.
测试脚本:
test1.sh
echo "test1.sh" >/home/kehao/result1.txt
hostname -s >>/home/kehao/result1.txt
hostname -i >>/home/kehao/result1.txt
id >>/home/kehao/result1.txt
chown kehao: /home/kehao/result1.txt
echo "I am $(hostname -i) :)"
运行日志:
kehao@kehaopcs ~/remote_exec $ ./remote_x86 put
2024/02/04 16:59:32 start put file...
2024/02/04 16:59:32 progress [2/3]...
2024/02/04 16:59:32 [172.18.0.3:22] upload /home/kehao/test1.sh to /home/kehao.
2024/02/04 16:59:32 [172.18.0.3:22] upload /home/kehao/test1.sh finished!
2024/02/04 16:59:32 progress [1/3]...
2024/02/04 16:59:32 [172.18.0.4:22] upload /home/kehao/test1.sh to /home/kehao.
2024/02/04 16:59:32 [172.18.0.4:22] upload /home/kehao/test1.sh finished!
2024/02/04 16:59:33 progress [0/3]...
2024/02/04 16:59:34 [127.0.0.1:23] upload /home/kehao/test1.sh to /home/kehao.
2024/02/04 16:59:34 [127.0.0.1:23] upload /home/kehao/test1.sh finished!
2024/02/04 16:59:34 put file finished.
kehao@kehaopcs ~/remote_exec $ ./remote_x86 exec
2024/02/04 16:59:37 start execute command...
2024/02/04 16:59:37 progress [2/3]...
2024/02/04 16:59:38 [172.18.0.3:22] execute (/bin/sh /home/kehao/test1.sh).
2024/02/04 16:59:38 [172.18.0.3:22] execute (/bin/sh /home/kehao/test1.sh) result:
I am 172.18.0.3 :)
[root@5f0c9135f133 ~]#
2024/02/04 16:59:38 [172.18.0.3:22] execute command finished!
2024/02/04 16:59:38 progress [1/3]...
2024/02/04 16:59:38 [172.18.0.4:22] execute (/bin/sh /home/kehao/test1.sh).
2024/02/04 16:59:38 [172.18.0.4:22] execute (/bin/sh /home/kehao/test1.sh) result:
I am 172.18.0.4 :)
[root@05d92c6bf1a1 ~]#
2024/02/04 16:59:38 [172.18.0.4:22] execute command finished!
2024/02/04 16:59:44 progress [0/3]...
2024/02/04 16:59:45 [127.0.0.1:23] execute (/bin/sh /home/kehao/test1.sh).
2024/02/04 16:59:45 [127.0.0.1:23] execute (/bin/sh /home/kehao/test1.sh) result:
I am 172.18.0.5 :)
[root@1244ba6621fc ~]#
2024/02/04 16:59:45 [127.0.0.1:23] execute command finished!
2024/02/04 16:59:45 execute command finished.
kehao@kehaopcs ~/remote_exec $ ./remote_x86 get
2024/02/04 16:59:51 start get file...
2024/02/04 16:59:51 progress [2/3]...
2024/02/04 16:59:51 [172.18.0.3:22] download file from /home/kehao/result1.txt to /home/kehao/result.
2024/02/04 16:59:51 [172.18.0.3:22] download /home/kehao/result1.txt finished!
2024/02/04 16:59:51 progress [1/3]...
2024/02/04 16:59:51 [172.18.0.4:22] download file from /home/kehao/result1.txt to /home/kehao/result.
2024/02/04 16:59:51 [172.18.0.4:22] download /home/kehao/result1.txt finished!
2024/02/04 16:59:53 progress [0/3]...
2024/02/04 16:59:53 [127.0.0.1:23] download file from /home/kehao/result1.txt to /home/kehao/result.
2024/02/04 16:59:53 [127.0.0.1:23] download /home/kehao/result1.txt finished!
2024/02/04 16:59:53 get file finished.
操作结果:
远端
kehao@kehaopcs ~/remote_exec $ docker exec -u kehao test-ssh1 bash -c 'ls -l ~'
total 24
-rw-r--r--. 1 kehao kehao 146 Feb 4 16:59 result1.txt
-rw-r--r--. 1 kehao kehao 146 Feb 4 16:59 result2.txt
-rw-rw-r--. 1 kehao kehao 319 Feb 4 16:59 test1.sh
-rw-rw-r--. 1 kehao kehao 10 Feb 4 16:59 test1.txt
-rw-rw-r--. 1 kehao kehao 319 Feb 4 16:59 test2.sh
-rw-rw-r--. 1 kehao kehao 10 Feb 4 16:59 test2.txt
本地:
kehao@kehaopcs ~/remote_exec $ ls -l /home/kehao/result/
total 64
-rw-r--r--. 1 kehao manager 146 Feb 4 16:59 127.0.0.1_23_result1.txt
-rw-r--r--. 1 kehao manager 146 Feb 4 16:59 172.18.0.3_22_result1.txt
-rw-r--r--. 1 kehao manager 146 Feb 4 16:59 172.18.0.4_22_result1.txt
kehao@kehaopcs ~/remote_exec $ cat /home/kehao/result/172.18.0.3_22_result1.txt
test1.sh
4c2db381a3d8
172.18.0.3
uid=0(root) gid=0(root) groups=0(root)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。