gnu watch:在终端左下角对齐
我想每 N 秒在 mysql 查询上应用一次 watch 命令,但希望将结果放在终端的左下角而不是左上角:
watch -n 120 "mysql_query" | column -t"
显示我的结果,如下所示:
--------------------------
|xxxxxxxxxxx |
|xxxxxxxxxxx |
|xxxxxxxxxxx |
| |
| |
--------------------------
而我希望它们像这样:
--------------------------
| |
| |
|xxxxxxxxxxx |
|xxxxxxxxxxx |
|xxxxxxxxxxx |
--------------------------
建议?
I want to apply a watch command on a mysql query every N seconds, but would like to have the results on the bottom left of the terminal instead of the top left:
watch -n 120 "mysql_query" | column -t"
Shows my results like so:
--------------------------
|xxxxxxxxxxx |
|xxxxxxxxxxx |
|xxxxxxxxxxx |
| |
| |
--------------------------
Whereas I would like them to have like so:
--------------------------
| |
| |
|xxxxxxxxxxx |
|xxxxxxxxxxx |
|xxxxxxxxxxx |
--------------------------
Suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有看到直接的方法来做到这一点,但我设法使用以下方法强制它工作。我还没有对此进行充分测试,因此我不能保证这在所有情况下都有效。
使用此脚本:
在
watch
调用时对命令的输出进行后处理(假设脚本保存为align_bottom
,使其可执行,并存储在watch
中的某个位置) code>$PATH):脚本的作用:
watch
输出的可见区域cat
之后的head
命令即可。tail
步骤 (3) 和 (4) 的输出,因此多余的填充被删除,最终输出紧贴watch
我不得不承认这看起来有点黑客,但是希望它能让您更接近您想要实现的目标。
更新:
也应该可以将其实现为一个函数,这样它就可以轻松地放在
.bashrc
中。用法是相同的:
请注意,
watch
使用sh -c
运行给定的命令,因此,正如丹尼斯在评论中指出的那样,在不链接的系统上>/bin/sh
到/bin/bash
上面显示的函数方法将不起作用。使用sign 可以使其工作:
但为了可移植性和可用性,简单地使用shell 脚本方法会更干净。
I don't see a straight-forward way to do this, but I managed to force it to work using the following approach. I haven't fully tested this so I cannot guarantee that this will work in all situations.
Using this script:
Post process the output of your command as it is called by
watch
e.g. (assuming the script was saved asalign_bottom
, made executable, and store somewhere within your$PATH
):What the script does:
watch
outputhead
command aftercat
.tail
the output of steps (3) and (4) so excess padding is removed and the final output fits snugly withinwatch
I have to admit this seems a little hackish, but hopefully it gets you closer to what you're trying to achieve.
Update:
It should also be possible to implement that as a function instead just so it can sit comfortably in
.bashrc
.Usage would be the same:
Note that
watch
runs the given command usingsh -c
, therefore, as Dennis pointed out in the comments, on systems that does not link/bin/sh
to/bin/bash
the function approach shown above will not work.It is possible to make it work usign:
but for portability and usability, it's cleaner to simply use the shell script approach.
我不知道
watch
是否可以做到这一点,但我要做的是使用另一种工具来拥有多个终端,并根据watch
正在运行的终端调整大小我的需要。其中一些有用的工具是:
我希望这有帮助。
I don't know if
watch
can do that, but what I'd do is use another tool to have multiple terminals and resize the one in whichwatch
is running according to my needs.A couple of these tools that can be useful are:
I hope this helps.