1

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.

2
  • 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, 2010 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 ;-) Dec 30, 2010 at 19:12

3 Answers 3

2

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.

3
  • 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. Dec 30, 2010 at 19:19
  • @Pascal: See my edited answer. Dec 30, 2010 at 20:00
  • Thank you very much Dennis, that's exactly what I was looking for :-) BTW, the package (on Ubuntu) is libnotify-bin. Jan 22, 2011 at 15:11
2

You can use watch like:

$ watch -n5 "ls | wc -l"

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

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .