Linux下批量管理工具pssh使用方法(2)

b)批量上传文件或目录(pscp.pssh命令)
批量上传本地文件/mnt/test.file到远程服务器上的/tmp目录:
[root@linuxidc ~]# pscp.pssh -l root -h hosts.txt /mnt/test.file /tmp/
[1] 16:18:05 [SUCCESS] 192.168.1.105
[2] 16:18:05 [SUCCESS] 192.168.1.109
[3] 16:18:05 [SUCCESS] 192.168.1.101
[4] 16:18:05 [SUCCESS] 192.168.1.118

批量上传本地文件/mnt/test.file、/mnt/aa.file、/mnt/bb.file到远程服务器上的/tmp目录:
[root@linuxidc ~]# pscp.pssh -l root -h hosts.txt /mnt/test.file /mnt/aa.file /mnt/bb.file /tmp/
[1] 16:22:50 [SUCCESS] 192.168.1.109
[2] 16:22:50 [SUCCESS] 192.168.1.105
[3] 16:22:50 [SUCCESS] 192.168.1.118
[4] 16:22:50 [SUCCESS] 192.168.1.101
或者:
[root@linuxidc ~]# pscp.pssh -l root -h hosts.txt /mnt/{test.file,aa.file,bb.file} /tmp/
[1] 16:23:44 [SUCCESS] 192.168.1.109
[2] 16:23:44 [SUCCESS] 192.168.1.105
[3] 16:23:44 [SUCCESS] 192.168.1.101
[4] 16:23:44 [SUCCESS] 192.168.1.118

批量上传本地目录/mnt/zhong到远程服务器上的/tmp目录(上传目录需要添加-r参数)
[root@linuxidc ~]# pscp.pssh -l root -h hosts.txt -r /mnt/zhong /tmp/
[1] 16:19:36 [SUCCESS] 192.168.1.109
[2] 16:19:36 [SUCCESS] 192.168.1.105
[3] 16:19:36 [SUCCESS] 192.168.1.101
[4] 16:19:36 [SUCCESS] 192.168.1.118

批量上传本地目录/mnt/zhong、/mnt/aa、/mnt/vv到远程服务器上的/tmp目录
[root@linuxidc ~]# pscp.pssh -l root -h hosts.txt -r /mnt/zhong /mnt/aa /mnt/vv /tmp/
[1] 16:21:02 [SUCCESS] 192.168.1.105
[2] 16:21:02 [SUCCESS] 192.168.1.109
[3] 16:21:02 [SUCCESS] 192.168.1.101
[4] 16:21:02 [SUCCESS] 192.168.1.118
或者:
[root@linuxidc ~]# pscp.pssh -l root -h hosts.txt -r /mnt/{zhong,aa,vv} /tmp/
[1] 16:22:00 [SUCCESS] 192.168.1.109
[2] 16:22:00 [SUCCESS] 192.168.1.105
[3] 16:22:00 [SUCCESS] 192.168.1.101
[4] 16:22:00 [SUCCESS] 192.168.1.118

c)批量下载文件或目录(pslurp命令)
批量下载服务器上的某文件到本地,不用担心重名问题,因为pssh已经建立了以文件列表内的ip为名称的目录来存放下载的文件
[root@linuxidc ~]# pslurp -l root -h hosts.txt /etc/hosts .
[1] 16:32:01 [SUCCESS] 192.168.1.109
[2] 16:32:01 [SUCCESS] 192.168.1.105
[3] 16:32:01 [SUCCESS] 192.168.1.101
[4] 16:32:01 [SUCCESS] 192.168.1.118
[root@linuxidc ~]# ll
total 123
drwxr-xr-x. 2 root root 4096 Feb 8 16:32 192.168.1.101
drwxr-xr-x. 2 root root 4096 Feb 8 16:32 192.168.1.105
drwxr-xr-x. 2 root root 4096 Feb 8 16:32 192.168.1.109
drwxr-xr-x. 2 root root 4096 Feb 8 16:32 192.168.1.118
[root@linuxidc ~]# ll 192.168.1.101
total 4
-rw-r--r--. 1 root root 224 Feb 8 16:32 hosts
[root@linuxidc ~]# ll 192.168.1.109
total 4
-rw-r--r--. 1 root root 252 Feb 8 16:32 hosts
[root@linuxidc ~]# ll 192.168.1.105
total 4
-rw-r--r--. 1 root root 252 Feb 8 16:32 hosts
[root@linuxidc ~]# ll 192.168.1.118
total 4
-rw-r--r--. 1 root root 212 Feb 8 16:32 hosts

另外特别注意:
上面的批量下载操作,只能下载到本地的当前目录下,不能在命令中跟指定的路径:
[root@linuxidc ~]# pslurp -l root -h hosts.txt /etc/hosts /mnt/
[1] 16:34:14 [FAILURE] 192.168.1.109 Exited with error code 1
[2] 16:34:14 [FAILURE] 192.168.1.105 Exited with error code 1
[3] 16:34:14 [FAILURE] 192.168.1.101 Exited with error code 1
[4] 16:34:14 [FAILURE] 192.168.1.118 Exited with error code 1

要想下载到本机的/mnt目录下,正确的做法是先切换到/mnt目录下,然后再执行下载命令:(列表文件要跟全路径)
[root@linuxidc ~]# cd /mnt/
[root@linuxidc mnt]# pslurp -l root -h /root/hosts.txt /etc/hosts ./
[1] 16:34:34 [SUCCESS] 192.168.1.109
[2] 16:34:34 [SUCCESS] 192.168.1.105
[3] 16:34:34 [SUCCESS] 192.168.1.118
[4] 16:34:34 [SUCCESS] 192.168.1.101
[root@linuxidc mnt]# ll
total 16
drwxr-xr-x. 2 root root 4096 Feb 8 16:34 192.168.1.101
drwxr-xr-x. 2 root root 4096 Feb 8 16:34 192.168.1.105
drwxr-xr-x. 2 root root 4096 Feb 8 16:34 192.168.1.109
drwxr-xr-x. 2 root root 4096 Feb 8 16:34 192.168.1.118

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/f521dea35d0dba73445956e189f9643e.html