【发布时间】:2021-11-11 12:06:24
【问题描述】:
我正在尝试创建一个脚本来从不同的远程服务器获取服务状态:
#!/bin/bash
USERNAME=vagrant
isengine=(server1 server2 server3 server4 server5)
isengine_services=( ds.rc DFDServer ISFAgents ODFEngine)
for h in "${isengine[@]}"
do
echo "${h}" >> test.txt
for i in "${isengine_services[@]}"
do
sshpass -p "mysecret" ssh -o StrictHostKeyChecking=no "${USERNAME}"@"${h}" "echo ${i}; systemctl status ${i} | grep Active" >> tmp.txt
done
done
cat tmp.txt
我得到如下所示的非常混乱的输出:
server1
ds.rc
Active: active (running) since Mon 2021-09-13 10:04:48 CEST; 3 days ago
DFDServer
Active: active (running) since Mon 2021-09-13 10:05:02 CEST; 3 days ago
ISFAgents
Active: active (running) since Mon 2021-09-13 10:04:46 CEST; 3 days ago
ODFEngine
Active: active (running) since Mon 2021-09-13 10:04:20 CEST; 3 days ago
是否可以让它看起来像下面这样:
server1
ds.rc Active: active (running) since Mon 2021-09-13 10:04:48 CEST; 3 days ago
DFDServer Active: active (running) since Mon 2021-09-13 10:05:02 CEST; 3 days ago
ISFAgents Active: active (running) since Mon 2021-09-13 10:04:46 CEST; 3 days ago
ODFEngine Active: active (running) since Mon 2021-09-13 10:04:20 CEST; 3 days ago
【问题讨论】: