Redirect an output from a script to a file and display it at a console simultaneously

Hi,

I'd like to redirect the STDOUT output from my script to a file and simultaneously display it at a console.

I've tried this command:

myscript.sh | tail -f

However, it doesn't end after the script finishes running

I've also tried this:

myscript.sh | tee ~/results.txt

But it writes the output to the file not before the myscript.sh script finishes executing

Do you have any ideas?
Thanks in advance

On Linux, you can write

script -c myscript.sh -f out

The script command will run myscript.sh and write the output to the screen and to out . The -f option makes script flush the buffer after every line of output.

1 Like

Thanks, it works fine

However, I work on the SunOS 5.10 so there is no possibility to run this command..

Sun's implementation of script does neither support the -c nor the -f option.