我正在编写一个bash脚本来格式化.csv文件的输出,在这里我使用pssh在1000台以上的服务器上运行命令(保存在/ tmp / hosts中),我能够通过一行来管理命令输出插入逗号“,”但不能将所有内容都放在一行 注意:服务器名称下面仅是一个示例,实际上,服务器名称是不同的,并且OS命令基于用户的输入。
我尝试在命令之间使用-'echo“ $(uname -a),$(date)”'在命令之间添加“,”。 但是无法保持一致,就像我在下面期望的那样。
我正在使用以下命令
pssh -h /tmp/hosts -x '-q -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no -o PreferredAuthentications=publickey -o PubkeyAuthentication=yes' -i 'echo "$(uname -a), $(date)"'
[1] 09:17:00 [FAILURE] SERVER1 Exited with error code 255
[2] 09:17:00 [SUCCESS] SERVER2
Linux SERVER2 3.0.101-108.84-default #1 SMP Fri Nov 30 15:57:27 UTC 2018 (7a72692) x86_64 x86_64 x86_64 GNU/Linux, Sat Jan 26 09:34:22 CET 2019
[3] 09:17:00 [SUCCESS] SERVER3
Linux SERVER3 3.0.101-108.84-default #1 SMP Fri Nov 30 15:57:27 UTC 2018 (7a72692) x86_64 x86_64 x86_64 GNU/Linux, Sat Jan 26 09:34:22 CET 2019
[4] 09:17:00 [SUCCESS] SERVER4
Linux SERVER4 3.0.101-108.84-default #1 SMP Fri Nov 30 15:57:27 UTC 2018 (7a72692) x86_64 x86_64 x86_64 GNU/Linux, Sat Jan 26 09:34:22 CET 2019
[5] 09:17:00 [SUCCESS] SERVER5
Linux SERVER5 3.0.101-108.84-default #1 SMP Fri Nov 30 15:57:27 UTC 2018 (7a72692) x86_64 x86_64 x86_64 GNU/Linux, Sat Jan 26 09:34:22 CET 2019
[6] 09:19:52 [FAILURE] HOST1 Exited with error code 255
[7] 09:19:52 [FAILURE] HOST2 Exited with error code 255
[8] 09:19:52 [FAILURE] HOST3 Timed out, Killed by signal 9
[9] 09:19:52 [FAILURE] HOST4 Timed out, Killed by signal 9
我期望输出如下
[FAILURE], SERVER1, Exited with error code 255
[SUCCESS], SERVER2, Linux SERVER2 3.0.101-108.84-default #1 SMP Fri Nov 30 15:57:27 UTC 2018 (7a72692) x86_64 x86_64 x86_64 GNU/Linux, Sat Jan 26 09:34:22 CET 2019
[SUCCESS], SERVER3, Linux SERVER3 3.0.101-108.84-default #1 SMP Fri Nov 30 15:57:27 UTC 2018 (7a72692) x86_64 x86_64 x86_64 GNU/Linux, Sat Jan 26 09:34:22 CET 2019
[SUCCESS], SERVER4, Linux SERVER4 3.0.101-108.84-default #1 SMP Fri Nov 30 15:57:27 UTC 2018 (7a72692) x86_64 x86_64 x86_64 GNU/Linux, Sat Jan 26 09:34:22 CET 2019
[SUCCESS], SERVER5, Linux SERVER5 3.0.101-108.84-default #1 SMP Fri Nov 30 15:57:27 UTC 2018 (7a72692) x86_64 x86_64 x86_64 GNU/Linux, Sat Jan 26 09:34:22 CET 2019
[FAILURE], HOST1, Exited with error code 255
[FAILURE], HOST2, Exited with error code 255
[FAILURE], HOST3, Timed out Killed by signal 9
[FAILURE], HOST4, Timed out Killed by signal 9
答案 0 :(得分:0)
换行符由pssh
实用程序插入。您可以尝试在--inline
实用程序中使用选项--inline-stdout
或pssh
。或使用-o
选项设置输出目录,然后使用bash脚本根据您的需要正确格式化输出。
答案 1 :(得分:-1)
grep pattern file | awk '{print}' ORS='" '