1

I'm running a time dd command in a shell script, and I'd like to output the results to a file, and print it out on the screen. The line that I'm currently running is:

(time dd of=$dest_filepath if=$src_filepath bs=$block_size count=$block_count) >> $log_file 2>&1 &

Although that is leaving me with an empty file and doesn't output to screen. What would I need to do in order to do all three things?

Note that I'm running this in an embedded system with a Busybox installation which does not include tee so this isn't a duplicate of this question.

  • Have you looked for man tee – Valentin Bajrami Oct 15 '14 at 11:00
  • 1
    Why don't you have tee? What OS are you using? What output do you expect in your file? The time or the dd or both? – terdon Oct 15 '14 at 11:00
  • It's a cut down version of Linux running on busybox. I don't have it because of how cut down the version was - I didn't have bash until I explicitly enables it and rebuilt. I'm expecting both time and dd to output to file. @terdon – Yann Oct 15 '14 at 11:03
3

What you're showing works as expected on my system. Are you sure you're using bash and not sh? In any case, I tried with dash and with busybox's sh and it worked there too. In the absence of tee, I think the only solution will be to cat $logfile after the command is finished.

Another possibility would be to make a link to busybox called tee and attempt to run that. The busybox that came with my Debian supports that but I don't know if yours will:

ln -s /bin/busybox /bin/tee

Then, try running tee normally.

If you really can't get tee, your only other option would be something like this:

foo=$( ( time dd if="file1" of="file2" bs=12 count=5 ) 2>&1 &)
echo "$foo"
echo "$foo" >> logfile
  • I'm not sure that cating it is really a viable option, as I'm running the command thousands of times, so catting the file would print all of the outputs every time. – Yann Oct 15 '14 at 11:17
  • @Yann4 did you try linking to busybox as tee? In any case, you're working with a minimal system, you can expect some loss of functionality. If you can't get tee to work, there's no way around catting. The only other choice would be to save the output as a variable, echo it and then print it to the file. – terdon Oct 15 '14 at 11:20
  • It's not on the system, I'd have to recompile the kernel to get it there. – Yann Oct 15 '14 at 11:22
  • The Busybox shipped by Debian includes most utilities with most features. It isn't a reliable indicator of what might be found in Busybox instances on very small systems. A lot of things are optional when you compile Busybox. If the tee utility had been included, the tee command would presumably exist already. For example, my router's Busybox has 97 utilities, while Debian's has 200. – Gilles 'SO- stop being evil' Oct 15 '14 at 22:49
-2

You can use the tee command. Here i have grouped the commands time and dd using the code block so that they will be treated as a single command and their output can be handled easily.

{ time dd of=$dest_filepath if=$src_filepath bs=$block_size count=$block_count; } 2>&1|tee $log_file

Make note of the ; at the end of the second command. This is mandatory for code blocks to work.

Incase if you dont want to use tee then you might think about this

{ time dd of=$dest_filepath if=$src_filepath bs=$block_size count=$block_count; } 2>&1 &> $log_file;cat $log_file
  • I explicitly said in the question that I needed to do it without tee – Yann Oct 15 '14 at 11:17
  • why cant you create a symbolic link of busybox pointing to tee for this purpose ? – Kannan Mohan Oct 15 '14 at 11:30
  • 1
    How about tail -f $log_file ? – wurtel Oct 15 '14 at 12:31
  • @KannanMohan Creating a symlink is highly unlikely to help. If tee had been included in that busybox executable, there should be a symlink for it already. – Gilles 'SO- stop being evil' Oct 15 '14 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.