当前位置:网站首页>Script design for automatic login and command return
Script design for automatic login and command return
2022-06-24 16:15:00 【mariolu】
Before the holiday, we were inspecting the health of the machine , You will need to use a batch script . For example, it is common to execute commands in batches for a bunch of online physical machines , View process health status , Is there any setting crontab Monitor auto pull script , Are there any exceptions in the log .
The dumbest way is to go one by one ip Log in to perform these operations . But if there are dozens of machines on the platform , So it is not very realistic to do manual work in batches . So we usually have the following methods .
One 、 Use polysh:
Polysh( Formerly known as Group Shell or gsh) It's a remote Shell multiplexer . It can be in a shell The program controls multiple remote devices at a time shell Program . Unlike other command schedulers , It's interactive , The interface looks like the following .
Two 、 Use ssh Carry out orders , And then use while Cycle batch execution and recycle results
But in general ssh Considering safety , It will be designed that the password must be entered manually , So here's another one sshpass Auxiliary input password .
sshpass -p [your password] ssh [user]@[your ip] [your shell command]
Notice that many machines log in for the first time , There is no trust that generates credentials and places them locally host In the list .
So you need to add the ignore option -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no , Otherwise, automatic login will fail .
-t Option is to force the assignment of pseudo terminals .
such sshpass It can deliver ssh A password , And then let ssh Sign in
2.1 Batch file
Suppose we have a file now [ip list file] There is a pair of ip list , A line of one ip. Then you can use while Loop processing .
while read line; do sshpass -p [your password] ssh -t -no UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no [user]@"$line" [your command]; done < [ip list file]
Notice here ssh With one -n Options ,ssh Because it reads by default stdin.
-n Give Way / dev / null Redirect to stdin( actually , Prevent reading from standard input ). It has to be added here -n, or while It will only cycle once and exit .
边栏推荐
- Leetcode 139. Mot break word Split (medium)
- Global and Chinese markets of Leyte coin exchange 2022-2028: Research Report on technology, participants, trends, market size and share
- Flink Kubernetes Application部署
- Solution to the problem that FreeRTOS does not execute new tasks
- The catch-up of domestic chips has scared Qualcomm, the leader of mobile phone chips in the United States, and made moves to cope with the competition
- Global and Chinese markets of natural insect repellents 2022-2028: Research Report on technology, participants, trends, market size and share
- C. K-th not divisible by n (Mathematics + thinking) codeforces round 640 (Div. 4)
- Install the imagemagick7.1 library and the imageick extension for PHP
- Global and Chinese markets of stainless steel barbecue ovens 2022-2028: Research Report on technology, participants, trends, market size and share
- 微信公众号调试与Natapp环境搭建
猜你喜欢

CAP:多重注意力机制,有趣的细粒度分类方案 | AAAI 2021

C. Three displays codeforces round 485 (Div. 2)

一文详解JackSon配置信息
![[my advanced OpenGL learning journey] learning notes of OpenGL coordinate system](/img/21/48802245fea2921fd5e4a9a2d9ad18.jpg)
[my advanced OpenGL learning journey] learning notes of OpenGL coordinate system

Solution to the problem that FreeRTOS does not execute new tasks

60 divine vs Code plug-ins!!

SIGGRAPH 2022 | 真实还原手部肌肉,数字人双手这次有了骨骼、肌肉、皮肤

How to expand disk space on AWS host
![[download attached] installation and simple use of Chinese version of awvs](/img/3b/f26617383690c86edff465c9a1099e.png)
[download attached] installation and simple use of Chinese version of awvs

The equipment is connected to the easycvr platform through the national standard gb28181. How to solve the problem of disconnection?
随机推荐
I just came back from the Ali software test. I worked for Alibaba P7 in 3+1, with an annual salary of 28*15
SQL multi table updating data is very slow
嵌入式开发基础之线程间通信
2021-04-28: force buckle 546, remove the box. Give some boxes of different colors
How to expand disk space on AWS host
D. Solve The Maze(思维+bfs)Codeforces Round #648 (Div. 2)
企业安全攻击面分析工具
Cap: multiple attention mechanism, interesting fine-grained classification scheme | AAAI 2021
Software test [high frequency] interview questions sorted out by staying up late (latest in 2022)
2021-05-03: given a non negative integer num, how to avoid circular statements,
一文详解JackSon配置信息
My network relationship with "apifox"
Little red book, hovering on the edge of listing
Understanding of deep separable convolution, block convolution, extended convolution, transposed convolution (deconvolution)
Golang+redis reentrant lock
微信公众号调试与Natapp环境搭建
How to obtain ECS metadata
一文详解JackSon配置信息
Logging is not as simple as you think
2021-04-18: given a two-dimensional array matrix, the value in it is either 1 or 0,