0

I have a few little scripts that I use for monitoring some aspects of our application that reside in an infinite loop with a 3 second sleep and simply display the output of ps aux | grep -i app_name or mysql -e "SHOW SLAVE STATUS\G" just so I can easily watch for a few mins without hitting any keys, what I'd like to know is how I could 'refresh' the values on the screen instead of appending to them, I guess the best example I have is of top, it refreshes values instead of continuously printing to the screen.

Any help would be extremely appreciated.

Thanks

4 Answers 4

5

Try watch utility. It runs arbitrary command in configurable interval (-n flag). It also can highlight differences in output between refreshes (-d flag).

Sign up to request clarification or add additional context in comments.

1 Comment

Great work. watch is very cool, never knew about it before. Thanks!
2

you can include the "clear" command in your loop (without looking at your code)

2 Comments

Argh, so easy! Works beautifully, thanks! (I feel so silly!) :)
but it would clear the entire screen.. isn't there a way to delete a line on stdout just like using \b in C
1

You can also use echo -n -e "\b" to undo your previous output together with echo -n "output" to maintain your new output on the cleared line

Comments

0

The probably simplest way:

watch -n 3 'ps aux | grep -i app_name'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.