Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm looking to execute a command at a given interval and display the result in a growl-like window. Is there an easy way to do that?

For example, I've a job running that resizes images and I would like to execute ls|wc -l every 5 minutes to check the progress.

share|improve this question
    
You say "growl-like", but then specify command-line. That makes the question ambiguous. Do you want GUI notifications from your command-line script, or are you okay with an all-in-the-terminal-window approach? –  mattdm Dec 6 '10 at 16:21
    
I want to execute a command in a terminal, continue to work in other windows and have notifications about the progress of the command running in the terminal. So, not ok for all-in-the-terminal-window approach ;-) –  Pascal Polleunus Dec 30 '10 at 19:12
add comment

3 Answers 3

up vote 2 down vote accepted

Install incron and have it execute your notification when there are changes in the directory. In your script that is run by incron could touch a file, if it's been at least five minutes since it was last touched send your notification (using zenity, or similar).

Edit:

Another option is notify-send which is usually in a package named something like "libnotify".

This will display a file count near the upper-left corner for three seconds every five minutes (and stop after 30 minutes):

start=$SECONDS
while (( $SECONDS < start + 30 * 60 ))
do
    if (( ! ( ($SECONDS - start) % (5 * 60) ) ))
    then
        notify-send --expire-time=3000 --hint=int:x:0 --hint=int:y:0 $(ls | wc -l)&
        sleep 1
    fi
done

Of course, you could just do sleep 5m.

share|improve this answer
    
Thanks but zenity is not really what I want. I'm looking for something like a transparent window that appears on the top-left corner of the screen and automatically fades away after a few seconds. –  Pascal Polleunus Dec 30 '10 at 19:19
    
@Pascal: See my edited answer. –  Dennis Williamson Dec 30 '10 at 20:00
    
Thank you very much Dennis, that's exactly what I was looking for :-) BTW, the package (on Ubuntu) is libnotify-bin. –  Pascal Polleunus Jan 22 '11 at 15:11
add comment

You can use watch like:

$ watch -n5 "ls | wc -l"

This will execute the command ls | wc -l every five seconds.

share|improve this answer
add comment

Like Khaled but with a twist:

watch -d -n 5 'ls | wc -l'

-d will show differences from one snapshot to the next, making it obvious when things change.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.