Hi, i agree with what der.hans advised.
With long running programs and the risk that they get aborted by Ctrl+C, i would also advise "tee" option -i. It makes sure that all output gets written to the file before "tee" aborts. ... | tee -a -i ~/my_logfile As long as the logfile path is a single word (i.e. without blanks or such), you may put the whole "tee" run into a variable to get less ugly code: # Define redirection command tee="tee -a -i $HOME/my_logfile" # Remove old log rm $HOME/my_logfile # Do the work while ... ... echo "Block count: "$blocks | $tee (The variable $tee does not work with "~" instead of "$HOME".) > # need code here for /dev/sr0 to be "ready" You could use xorriso to do the waiting (and the tray loading if needed): xorriso -outdev /dev/sr0 In the good old times, one could also do eject -t or dd if=/dev/sr0 count=1 of=/dev/null But a kernel regression between 2.6 and 3.16 spoiled the feature that the tray goes in on the first read attempt and that reading waits until the drive reports to be ready. --------------------------------------------------------------------- Unrelated nitpicking: > xorriso -indev /dev/sr0 -data_cache_size 512 1024 -check_media > data_to=$FILENAME I wonder why you need 1 GiB of memory cache. It will only be of help while -indev loads the directory tree, which i assume is much smaller than 1 GiB. 128 MiB would be: -data_cache_size 64 1024 You may avoid loading the directory tree by using -outdev instead of -indev: xorriso -outdev /dev/sr0 -check_media use=outdev data_to=$FILENAME -- The parameter range of -check_media should be ended by "--", so that one can later append further xorriso commands after -check_media. Maybe you should check for xorriso failure: xorriso ... if test "$?" = 0 then echo "xorriso run succeeded" else echo echo " XORRISO RUN FAILED !" echo fi Have a nice day :) Thomas