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?
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
watche.g. (assuming the script was saved asalign_bottom, made executable, and store somewhere within your$PATH):What the script does:
watchoutputheadcommand aftercat.tailthe output of steps (3) and (4) so excess padding is removed and the final output fits snugly withinwatchI 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
watchruns the given command usingsh -c, therefore, as Dennis pointed out in the comments, on systems that does not link/bin/shto/bin/bashthe 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.