Is it possible to follow a command (run repeatedly)? as one would follow a file using tail -f?

I have a script which produces a file ‘Detail.out’. I know that the script is completed whenever the file contains a certain number of lines (roughly 21025). So I find myself sitting at the command prompt running:

[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e38e86a3908c8e86948b869186">[email protected]</a> myDir]$ wc -l */Detail.out
  21025 A/Detail.out
  21025 B/Detail.out
  21025 C/Detail.out
  12995 D/Detail.out
  10652 E/Detail.out
   3481 F/Detail.out
  21027 G/Detail.out
  21025 H/Detail.out
  21025 I/Detail.out
  ...   ...

I’ve used tail -f to watch a specific file, but I’d like to follow the output of the wc -l */Detail.out command shown above. Is this possible? I’m currently using tcsh in Ubuntu 11.04 if that matters.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Try the watch command, although I suspect just about everyone has written their own version at one time or another. (The cheapie version is while :; do clear; "[email protected]"; sleep 5; done.)

Method 2

Not sure if you know that but you can redirect the output of a program to a file as well. See http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html Thus, another way might be to simply redirect the output to a file and then use tail on that file as you are already used to do.

$ find . -name "Detail.out" | xargs wc -l >> detail-out-list.txt

And in another Terminal you could run $ tail -f detail-out-list.txt as you are used to.

As Celeb noted that leaves some file around which may what you want (to further inspect that file or to have some history) or not and nothing gets executed periodically like watch does for you.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x