热度 2| |||
bytedance@C02FT5LHMD6R Downloads % git clone https://github.com/bytedance/batchRun.git Cloning into 'batchRun'... remote: Enumerating objects: 32, done. remote: Counting objects: 100% (32/32), done. remote: Compressing objects: 100% (25/25), done. remote: Total 32 (delta 1), reused 32 (delta 1), pack-reused 0 Receiving objects: 100% (32/32), 800.59 KiB | 1.20 MiB/s, done. Resolving deltas: 100% (1/1), done.
[root@ic-admin1 tools]# cd batchRun/ [root@ic-admin1 batchRun]# ls bin common config data docs install.py LICENSE.txt Notice.txt patch README requirements.txt scripts tools
[root@ic-admin1 batchRun]# which python3 /ic/software/tools/python3/3.8.8/bin/python3 [root@ic-admin1 batchRun]# [root@ic-admin1 batchRun]# pip3 install -r requirements.txt Looking in indexes: https://bytedpypi.byted.org/simple/ Requirement already satisfied: pexpect==4.8.0 in /ic/software/tools/python3/3.8.8/lib/python3.8/site-packages (from -r requirements.txt (line 1)) (4.8.0) Requirement already satisfied: ptyprocess>=0.5 in /ic/software/tools/python3/3.8.8/lib/python3.8/site-packages (from pexpect==4.8.0->-r requirements.txt (line 1)) (0.7.0)
[root@ic-admin1 batchRun]# python3 install.py >>> Check python version. Required python version : (3, 8) Current python version : (3, 8) >>> Generate script "/ic/data/usr/liyanqing.1987/tools/batchRun/bin/batch_run". >>> Generate script "/ic/data/usr/liyanqing.1987/tools/batchRun/tools/encrypt_python". >>> Generate script "/ic/data/usr/liyanqing.1987/tools/batchRun/tools/get_password". >>> Generate script "/ic/data/usr/liyanqing.1987/tools/batchRun/tools/save_password". >>> Generate script "/ic/data/usr/liyanqing.1987/tools/batchRun/tools/xssh". >>> Generate config file "/ic/data/usr/liyanqing.1987/tools/batchRun/config/config.py". Done, Please enjoy it.
# Specify host list, default is "host.list" on current configure directory. HOST_LIST = '/ic/data/usr/liyanqing.1987/tools/batchRun/config/host.list' # Set log directory. LOG_DIR = '/ic/data/usr/liyanqing.1987/tools/batchRun/data/log' # Default ssh command. DEFAULT_SSH_COMMAND = "ssh -o StrictHostKeyChecking=no" # Support host_ip fuzzy matching, could be "True" or "False". FUZZY_MATCH = True # Define timeout for ssh command, unit is "second". TIMEOUT = 10
#### Format #### # # Description # [group_name] # ip1 # ip2 <port2> # ip3 <hostname3> # ip4 <hostname4> <port4> # sub_group ################ ... # Login servers [LOGIN] ETX VNC # ETX login servers [ETX] 10.212.206.194 cmp194 10.212.206.195 cmp195 10.212.206.196 cmp196 10.212.206.207 cmp207 10.212.206.218 cmp218 # VNC login servers [VNC] 10.212.206.225 cmp225 10.212.206.235 cmp235 ...
[root@ic-admin1 batchRun]# tools/save_password -u liyanqing.1987 -p *** [root@ic-admin1 batchRun]# cat config/password.encrypted liyanqing.1987 46953b705ab979d47b81b6a5ee8fa0c7
[root@ic-admin1 batchRun]# module load cad [root@ic-admin1 batchRun]# which batch_run /ic/data/usr/liyanqing.1987/tools/batchRun/bin/batch_run
[root@ic-admin1 bin]# batch_run -h usage: batch_run.py [-h] [-H HOSTS [HOSTS ...]] [-G HOST_GROUPS [HOST_GROUPS ...]] [-lsf_queues LSF_QUEUES [LSF_QUEUES ...]] [-P] [-u USER] [-p PASSWORD] [-c COMMAND [COMMAND ...]] [-m MULTI_COMMANDS_FILE] [-t TIMEOUT] [-o {0,1,2,3,4}] [--list_hosts LIST_HOSTS [LIST_HOSTS ...]] optional arguments: -h, --help show this help message and exit -H HOSTS [HOSTS ...], --hosts HOSTS [HOSTS ...] Specify the host(s), could be host_ip or host_name, format is "host" or "host:port". "ALL" means all hosts on /ic/software/cad_tools/it/batchRun/config/host.list. "~<HOST>" means exclud the specified host. -G HOST_GROUPS [HOST_GROUPS ...], --host_groups HOST_GROUPS [HOST_GROUPS ...] Specify host group(s) which are on /ic/software/cad_tools/it/batchRun/config/host.list. "ALL" means all groups on /ic/software/cad_tools/it/batchRun/config/host.list. "~<GROUP>" means exclud the specified group. -lsf_queues LSF_QUEUES [LSF_QUEUES ...], --lsf_queues LSF_QUEUES [LSF_QUEUES ...] Get host list based on LSF queues. "ALL" means all LSF hosts. "~<QUEUE>" means exclud the specified queue. -P, --parallel Run command parallel on specified host(s), default is in serial. -u USER, --user USER Specify the user name when connectting host as. -p PASSWORD, --password PASSWORD Specify the user password when connectting host with. -c COMMAND [COMMAND ...], --command COMMAND [COMMAND ...] Specify command you want run on specified host(s). -m MULTI_COMMANDS_FILE, --multi_commands_file MULTI_COMMANDS_FILE Specify a script with multi commands, will execute line by line. -t TIMEOUT, --timeout TIMEOUT Specify ssh command timeout, default is 10 seconds. -o {0,1,2,3,4}, --output_message_level {0,1,2,3,4} Specify output message level, default is "3". "0" means silence; "1" only show host info; "2" only show one line output message; "3" show normal output message; "4" show verbose output message. --list_hosts LIST_HOSTS [LIST_HOSTS ...] List all or specified-group hosts on /ic/software/cad_tools/it/batchRun/config/host.list. "all" or "ALL" means all hosts on host list file. "<group>" means hosts on specified groups.
[root@ic-admin1 ~]# batch_run --list_hosts all GROUP : SERVICE 10.212.240.5 sftp-upload 5566 10.212.240.6 sftp-download 5566 10.212.240.12 ic-idm-01 ... GROUP : PHYSICAL LOGIN/ COMPUTING/
[root@ic-admin1 ~]# batch_run --list_hosts ETX GROUP : ETX 10.212.206.194 n212-206-194 10.212.206.195 n212-206-195 10.212.206.196 n212-206-196 10.212.206.207 n212-206-207 10.212.206.218 n212-206-218
[root@ic-admin1 ~]# batch_run -u ic_admin -p *** -H 10.212.206.194 -c whoami >>> 10.212.206.194 ic_admin
[root@ic-admin1 ~]# tools/save_password -u ic_admin -p ***
[root@ic-admin1 ~]# cat config/password.encrypted ic_admin adf95ce69c9e3cf62abe5d1460fb6b8a
[ic_admin@ic-admin1 ~]$ batch_run -G ETX -c "cat /etc/redhat-release" >>> 10.212.206.194 CentOS Linux release 7.9.2009 (Core) >>> 10.212.206.195 CentOS Linux release 7.9.2009 (Core) ...
[root@ic-admin1 bin]# batch_run -H 10.212.206.194 n212-206-195 -c hostname -o 2 >>> 10.212.206.194 n212-206-194 >>> n212-206-195 n212-206-195
[root@ic-admin1 ~]# batch_run -G ETX -c hostname -o 2 >>> 10.212.206.194 n212-206-194 >>> 10.212.206.195 n212-206-195 >>> 10.212.206.196 n212-206-196 >>> 10.212.206.207 n212-206-207 >>> 10.212.206.218 n212-206-218
[root@ic-admin1 ~]# batch_run -G ETX -H ~10.212.206.194 ~n212-206-195 -c hostname -o 2 >>> 10.212.206.196 n212-206-196 >>> 10.212.206.207 n212-206-207 >>> 10.212.206.218 n212-206-218
[root@ic-admin1 bin]# batch_run --lsf_queues a8-test swan -c hostname -o 2 >>> n232-132-012 n232-132-012 >>> n232-130-194 n232-130-194 >>> n212-206-210 n212-206-210
[root@ic-admin1 bin]# batch_run -c "cat /etc/redhat-release" -H 130 [FUZZY MATCH] 130 -> 10.212.204.130 [FUZZY MATCH] 130 -> 10.212.207.130 >>> 10.212.204.130 CentOS Linux release 7.9.2009 (Core) >>> 10.212.207.130 CentOS Linux release 7.6.1810 (Core)
[root@ic-admin1 ~]# cat /ic/ic_admin/touch_hostname.sh #!/bin/bash echo `hostname` touch `hostname`
[root@ic-admin1 ~]# batch_run -c /home/ic_admin/touch_hostname.sh -G ETX -o 2 >>> 10.212.206.194 n212-206-194 >>> 10.212.206.195 n212-206-195 >>> 10.212.206.196 n212-206-196 >>> 10.212.206.207 n212-206-207 >>> 10.212.206.218 n212-206-218 [root@ic-admin1 ~]# [root@ic-admin1 ~]# ls n212-206-194 n212-206-195 n212-206-196 n212-206-207 n212-206-218 touch_hostname.sh
[root@ic-admin1 ~]# rm -rf n212-20* [root@ic-admin1 ~]# batch_run -c /home/ic_admin/touch_hostname.sh -G ETX -o 2 -P >>> 10.212.206.195 >>> 10.212.206.207 >>> 10.212.206.194 >>> 10.212.206.218 >>> 10.212.206.196 >>> 10.212.204.130 n212-206-218 n212-206-194 n212-206-196 n212-206-195 n212-206-207 n212-204-130 [root@ic-admin1 ~]$ [root@ic-admin1 ~]$ ls n212-206-194 n212-206-195 n212-206-196 n212-206-207 n212-206-218 touch_hostname.sh
[root@ic-admin1 ~]# cat get_host_info cat /etc/redhat-release cat /proc/cpuinfo | grep name | sort | uniq cat /proc/meminfo | grep MemTotal
[root@ic-admin1 ~]# batch_run -H 10.212.207.130 -m get_host_info.sh >>> 10.212.207.130 CentOS Linux release 7.6.1810 (Core) model name : Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz MemTotal: 1056265940 kB
[liyanqing.1987@n212-206-194 ~]$ batch_run -G ETX -c nopassword_ssh.sh >>> 10.212.206.194 Generating public/private rsa key pair. Your identification has been saved in id_rsa. Your public key has been saved in id_rsa.pub. The key fingerprint is: SHA256:Dd+bRsE5+prVp/7UDbl6CR09ik/xWlbOuVktlf5ctkc liyanqing.1987@n212-206-194 The key's randomart image is: +---[RSA 2048]----+ | | | . . | | . = ..| | + o +.++| | S + +.B==| | +.*oOE| | O.**%| | = +oB+| | o .oo.o| +----[SHA256]-----+ >>> 10.212.206.195 Generating public/private rsa key pair. Your identification has been saved in id_rsa. Your public key has been saved in id_rsa.pub. ...
[liyanqing.1987@n212-206-194 ~]$ ssh 10.212.206.195 Last login: Sun Jan 8 10:30:32 2023 [liyanqing.1987@n212-206-195 ~]$
[root@ic-admin1 ~]# batch_run -H 10.212.207.130 -c "lsb_release -a" -o 0 [root@ic-admin1 ~]#
[root@ic-admin1 ~]# batch_run -H 10.212.207.130 -c "lsb_release -a" -o 1 >>> 10.212.207.130
[root@ic-admin1 ~]# batch_run -H 10.212.207.130 -c "lsb_release -a" -o 2 >>> 10.212.207.130 LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
[root@ic-admin1 ~]# batch_run -H 10.212.207.130 -c "lsb_release -a" -o 3 >>> 10.212.207.130 LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.6.1810 (Core) Release: 7.6.1810 Codename: Core
[root@ic-admin1 ~]# batch_run -H 10.212.207.130 -c "lsb_release -a" -o 4 >>> 10.212.207.130 /ic/software/cad_tools/it/batchRun/tools/run_ssh_command.py -c "ssh -XY -o StrictHostKeyChecking=no ic_admin@10.212.207.130 lsb_release \-a" -H 10.212.207.130 -p *** -t 10 ==== output ==== LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.6.1810 (Core) Release: 7.6.1810 Codename: Core ================
[root@ic-admin1 tools]$ ./save_password -h usage: save_password.py [-h] [-P PASSWORD_FILE] [-u USER] -p PASSWORD optional arguments: -h, --help show this help message and exit -P PASSWORD_FILE, --password_file PASSWORD_FILE Specify the user password file, default is "/ic/software/cad_tools/it/batch_run/config/password.encrypted". -u USER, --user USER Specify user name, deault is current user. -p PASSWORD, --password PASSWORD Specify user password.
[root@ic-admin1 tools]$ ./get_password -h usage: get_password.py [-h] [-P PASSWORD_FILE] [-u USER] optional arguments: -h, --help show this help message and exit -P PASSWORD_FILE, --password_file PASSWORD_FILE Specify the user password file, default is "/ic/software/cad_tools/it/batch_run/config/password.encrypted". -u USER, --user USER Specify the user name,default is current user.
[root@ic-admin1 tools]# ./essh 10.212.206.194 spawn ssh -XY -p 22 10.212.206.194 root@10.212.206.194's password: Last login: Sat May 21 13:28:59 2022 from 10.212.206.207 [root@cmp194-FPGA ~]#
[root@ic-admin1 tools]# xssh 194 [FUZZY MATCH] 194 -> 10.212.206.194 xterm -e "/ic/software/cad_tools/it/batch_run/tools/essh 10.212.206.194 22" &
[root@ic-admin1 tools]# xssh 130 [FUZZY MATCH] 130 -> 10.212.204.130 [FUZZY MATCH] 130 -> 10.212.207.130 Below are possible hosts: [0] 10.212.204.130 [1] 10.212.207.130 [2] None of above hosts Please choice one (number): 1 xterm -e "/ic/software/cad_tools/it/batch_run/tools/essh 10.212.207.130 22" &
[root@ic-admin1 batchRun]$ cat scripts/get_server_info/get_server_info.py #!/ic/software/tools/python3/3.8.8/bin/python3 # -*- coding: utf-8 -*- ... import os import re import socket ...
[root@ic-admin1 ~]$ batch_run -H 10.212.207.130 -c get_server_info.py >>> 10.212.207.130 ip : 10.212.207.130 hostname : n212-207-130 os : CentOS Linux release 7.6.1810 (Core) cpu : 96 mem : 1007G