Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to make a demo Virtual Machine. On the desktop, I have a script and it outputs stdout to foo.log (e.g. with some command > foo.log)

When I double click on the script, it generates the foo.log. However, I would like for the script to also present the stdout in real time (e.g. using tail -f foo.log).

How can I do this? Do I need to pipe the output to two places?

share|improve this question

This may not be the most elegant approach, but it appears to work:

Add the following to the script:

touch foo.log
uxterm -e "tail -f foo.log" &
some command > foo.log

with gnome-terminal, replace uxterm -e with gnome-terminal -x.

Thanks to the Hilltop Yodeler for directing me to this solution.

share|improve this answer
I was posting that sort of information. Use gnome-terminal -e to call your script, within your script use tee, but tail works as well. – bodhi.zazen Jan 24 '12 at 22:53

Unix's standard tee command allows you to redirect the command's standard input to one or more files and also print it to the standard output. So you can do something like|tee mylog.log

provided that just prints to standard output (which would actually simplify it)

To open a terminal windows when you click on icon, you can wrap it in another script:

xterm -e " | tee mylog.log; read -p FINISHED"

The difference with your solution is that you have a choice to either close the terminal window when the script finished or display "Press any key to continue..." message - with tail -f the terminal basically has no way of knowing when your script finished so you have to interrupt it with Ctrl-C.

Also, tail -f must be less efficient that printing directly to terminal, but this is probably not very important these days.

share|improve this answer
nope, that does not work; it neither writes a log file nor opens the terminal. Note that I am not executing the script from the terminal, I am executing it by clicking on the desktop icon that represents the script. – David LeBauer Jan 24 '12 at 22:30
The original solution was answering your question "how to pipe the output in two places" - to open the script in a terminal window you use xterm -e or any other terminal program. I updated the answer. – Sergey Jan 24 '12 at 23:03

I did Sergy's suggestion and if it worked, it may be a path problem. Here is the exact command I used and the result was an xterm opening, showing the output of the script and then says "Press return to close ". I suggest you add path in front of the script name, and possibly the log file name.

xterm -e "./ | tee ./mylog.log; read -p Press\ return\ to\ close\ "

All my version of did was to echo several lines, but it worked.

share|improve this answer

Your Answer


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.