上面脚本的输出如下:
$ cat /tmp/remote-test.sh | ssh daygeek@CentOS7.2daygeek.com Pseudo-terminal will not be allocated because stdin is not a terminal. ---------System Uptime-------------------------------------------- 03:14:09 up 2:19, 1 user, load average: 0.00, 0.01, 0.05 -
---------Memory Usage--------------------------------------------- total used free shared buff/cache available Mem: 1838 376 1063 11 398 1253 Swap: 2047 0 2047 -
---------Disk Usage----------------------------------------------- Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 27G 4.4G 23G 17% / devtmpfs 903M 0 903M 0% /dev tmpfs 920M 0 920M 0% /dev/shm tmpfs 920M 9.3M 910M 2% /run tmpfs 920M 0 920M 0% /sys/fs/cgroup /dev/sda1 1014M 179M 836M 18% /boot tmpfs 184M 12K 184M 1% /run/user/42 tmpfs 184M 0 184M 0% /run/user/1000 tmpfs 184M 0 184M 0% /run/user/0 -
---------Kernel Version------------------------------------------- Linux CentOS7.2daygeek.com 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux -
---------HostName Info-------------------------------------------- Static hostname: CentOS7.2daygeek.com Icon name: computer-vm Chassis: vm Machine ID: 002f47b82af248f5be1d67b67e03514c Boot ID: dca9a1ba06374d7d96678f9461752482 Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-957.el7.x86_64 Architecture: x86-64
8) 如何同时在多个远程系统上运行多条指令
下面的 bash 脚本允许用户同时在多个远程系统上运行多条指令。使用简单的 for 循环实现。
为了实现这个目的,你可以尝试 PSSH 命令 或 ClusterShell 命令 或 DSH 命令。
$ vi /tmp/multiple-host.sh -
for host in CentOS7.2daygeek.com CentOS6.2daygeek.com do ssh daygeek@CentOS7.2daygeek.com${host} "uname -a;uptime;date;w" done
(编辑:ASP站长网)
|