mysql 命令的输出未正确对齐标题(使用脚本)。 这是script.sh中的sql命令
#!/usr/bin/bash
echo "select * from hw_inventory "| mysql --host=localhost --user=root --database=monitor > /tmp/inventory
这在/tmp/inventory 中提供了以下输出
ip_address entity_index entity_physname entity_physdesc entity_serial
10.212.0.1 1000 Switch 1 WS-C3850-12S FOC1842U117
10.212.0.1 1009 Switch 1 - Power Supply A Switch 1 - Power Supply A LIT18300URD
10.212.0.1 1010 Switch 1 - Power Supply B Switch 1 - Power Supply B LIT183506NH
10.212.0.1 1034 Switch 1 FRU Uplink Module 1 2x1G 2x10G Uplink Module FOC18363NJX
正如您所看到的,对齐方式(制表符)与开关 1 的文本应在实体_physname 下开始的方式不同。 它需要类似于以下输出:
ip_address entity_index entity_physname entity_physdesc entity_serial
10.212.0.1 1000 Switch 1 WS-C3850-12S FOC1842U117
10.212.0.1 1009 Switch 1 - Power Supply A Switch 1 - Power Supply A LIT18300URD
10.212.0.1 1010 Switch 1 - Power Supply B Switch 1 - Power Supply B LIT183506NH
10.212.0.1 1034 Switch 1 FRU Uplink Module 1 2x1G 2x10G Uplink Module FOC18363NJX
有什么想法吗? 提前致谢
最佳答案
要格式化 mysql 的输出,请使用 -t
参数
"select * from hw_inventory "| mysql -t --host=localhost --user=root --database=monitor > /tmp/inventory
关于mysql - mysql输出的列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33875254/