In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how python implements lightweight automated operation and maintenance tools. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Pssh
A tool based on python that can execute commands on multiple servers and copy files. It provides several parallel tools based on ssh and scp.
Project: http://code.google.com/p/parallel-ssh/
Syntax:
Usage: pscp.pssh [OPTIONS] local remote
Common options:
-- version: view version-h: list of host files, content format "[user@] host [: port]"-H: host string Content format "[user@] host [: port]"-A: manually enter password mode-I: internal processing information output per server-l: user name used for login-p: number of concurrent threads [optional]-o: output directory of standard output file (optional)-e: output directory of standard error file (optional)-t:TIMEOUT timeout setting 0 unlimited [optional]-options for O:SSH-P: print out server return information-v: detailed mode
[example 1] batch execution of echo "hello pssh" to hosts in the list of host files through pssh.
[root@CentOS7 ~] # cat host.txt 172.20.200.200192.168.61 [root@CentOS7 ~] # pssh-h host.txt-I echo "hello pssh" [1] 16:31:10 [SUCCESS] 192.168.8.61hello pssh [2] 16:31:10 [SUCCESS] 172.20.200.200hello pssh Note: when ssh's key authentication is not supported, you can manually enter the password authentication batch execution instruction through the-An option.
[example 2] Save both standard error and standard correct redirection to the / app directory of the local host.
[root@CentOS7 ~] # pssh-h host.txt-o / app/-e / app/-I echo "hello pssh" [1] 16:52:32 [SUCCESS] 192.168.8.61hello pssh [2] 16:52:32 [SUCCESS] 172.20.200.200hello pssh [root@CentOS7] # ls / app/172.20.200.200 192.168.61 [root@CentOS7 ~] # cat / app/192.168.8.61 hello psshpscp.pssh command
Function: batch copy local files to remote hosts
Syntax:
[root@CentOS7 ~] # pscp.pssh-- helpUsage: pscp.pssh [OPTIONS] local remote
Options: basically the same as the pssh command, but there is a-r option to copy directories recursively
[example 1] batch copy the local / etc/fstab file to the / app directory of the host in the host list file
[root@CentOS7] # pscp.pssh-h host.txt / etc/fstab / app/ [1] 17:19:32 [SUCCESS] 192.168.8.61 [2] 17:19:32 [SUCCESS] 172.20.200.200 [root@CentOS7] # pssh-h host.txt-I ls / app/-l [1] 17:25:14 [SUCCESS] 192.168.8.61total 4 Mustang RWKul-1 root root 595 Nov 8 20:27 fstab [2 ] 17:25:14 [SUCCESS] 172.20.200.200total 4 Mustang RW Murray Rafe-1 root root 595 Nov 9 17:19 fstab
[example 2] bulk copy the local directory / test/ to the host's / app directory in the host file list
[root@CentOS7 ~] # pscp.pssh-h host.txt-r / test/ / app/ [1] 17:23:14 [SUCCESS] 192.168.8.61 [2] 17:23:14 [SUCCESS] 172.20.200.200 [root@CentOS7 ~] # pssh-h host.txt-I ls / app/-l [1] 17:26:33 [SUCCESS] 192.168.8.61total 8 Mustang Rwmuri-1 root root 595 Nov 8 20:27 fstabdrwxr -xr-x 2 root root 4096 Nov 8 20:33 test [2] 17:26:33 [SUCCESS] 172.20.200.200total 4 RW Nov Nov 9 17:19 fstabdrwxr-xr-x 2 root root 48 Nov 9 17:25 testpslurp Command
Function: batch copy the files of the remote host to the local, contrary to the function of the pscp.pssh command.
Syntax:
Pslurp [- vAr] [- h hosts_file] [- H [user@] host [: port]] [- l user] [- p par] [- o outdir] [- e errdir] [- t timeout] [- O options] [- xargs] [- X arg] [- L localdir] remote local (local name)
Options:
-L copies the files from the remote host to the given local directory, where local is the name after downloading to the local directory
[example] batch download the passwd files of the target server to the local directory / app, and rename it to user
[root@CentOS7] # pslurp-h host.txt-L / app// etc/passwd user [1] 17:35:38 [SUCCESS] 192.168.61 [2] 17:35:38 [SUCCESS] 172.20.200.200 [root@CentOS7] # tree / app//app/ ├── 172.20.200.200 │ └── user └── 192.168.61 └── user2 directories, 2 files Thank you for reading! This is the end of this article on "how to achieve lightweight automated operation and maintenance tools in python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.