我这方法是通过expect实现的。
安装expect
yum install -y expect
操作:
[[email protected] ~]# cat test.sh
/usr/local/mysql/bin/mysql -e "select version();"
[[email protected] ~]# ll test.sh
-rwxr-xr-x 1 root root 50 08-13 16:44 test.sh
[[email protected] ~]# sh test.sh
+------------+
| version() |
+------------+
| 5.1.49-log |
+------------+
[[email protected] ~]# sh test.sh >a.txt #直接这样是没有边框的。
[[email protected] ~]# cat a.txt
version()
5.1.49-log
[[email protected] ~]# cat mysql.exp #通过expect实现
#!/usr/bin/expect -f
set timeout -1
spawn ./test.sh
expect
[[email protected] ~]# expect mysql.exp >a.txt
[[email protected] ~]# cat a.txt
spawn ./test.sh #多了这行,内容到手,删除即可。
+------------+
| version() |
+------------+
| 5.1.49-log |
+------------+
mysql输出信息保留++--边框方法
时间: 2024-10-12 21:54:00