Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7088291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:46:57+00:00 2026-05-28T07:46:57+00:00

I want to apply a watch command on a mysql query every N seconds,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:46:57+00:00Added an answer on May 28, 2026 at 7:46 am

    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:

    #!/bin/bash
    TERM_HEIGHT=`tput lines`  # determine terminal height
    WATCH_BANNER_HEIGHT=2  # account for the lines taken up by the header of "watch"
    let VIS_LINES="TERM_HEIGHT - WATCH_BANNER_HEIGHT"  # height of visible area
    (yes " " | head -n $VIS_LINES; cat | head -n $VIS_LINES) | tail -n $VIS_LINES
    

    Post process the output of your command as it is called by watch e.g. (assuming the script was saved as align_bottom, made executable, and store somewhere within your $PATH):

    watch -n 120 "mysql_query | column -t | align_bottom"
    

    What the script does:

    1. Determine the height (number of lines) of the terminal
    2. Calculate the visible area of the watch output
    3. Print blank lines to pad the output (pushing the output down)
    4. Read in output from stdin, and trim it so we only show the top of the output if it extends beyond the screen. If you want to see the bottom of the output instead, simple remove the head command after cat.
    5. tail the output of steps (3) and (4) so excess padding is removed and the final output fits snugly within watch

    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.

    function align_bottom() {
      (( VIS = $(tput lines) - 2 ))  # height of visible area
      (yes " " | head -n $VIS; cat | head -n $VIS) | tail -n $VIS
    }
    typeset -fx align_bottom  # !! make it callable from subshell
    

    Usage would be the same:

    watch -n 120 "mysql_query | column -t | align_bottom"
    

    Note that watch runs the given command using sh -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:

    watch -n 120 "mysql_query | column -t | bash -c align_bottom"
    

    but for portability and usability, it’s cleaner to simply use the shell script approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to apply an ActionFilter in ASP.NET MVC to EVERY action I have
I want to apply right alignment on the last cell of every table row,
I want to apply NTFS-Search to our project. Our project have to find the
I have a style rule I want to apply to a tag when it
I have an idea and I want to apply it to my Application (C#
I want to apply some custom styling to the jquery loading dialog but can't
I want to apply the following awk command on files with extension *.txt awk
I want to apply an attribute which accepts a delegate as an argument, but
I want apply opacity for parent but I do not want the child element
I want to apply a function to every item of a list and store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.