Catching stderr from dd over ssh
Hi,
this might be an interesting one for the bash scripting gurus. I seem to break my teeth on it. The mission: - do a dd over ssh to trasnfer an image to another host - capture the dd PID on the other side - send a USR1 kill signal to it - capture that output on the original host It goes wrong on the last part. This is what I have before that step: dd if=image.gz | gzip -d | ssh host2 "dd of=/dev/vg1/lv1" & PID=`ssh host2 ps aux |grep dd|grep lx05|awk '{ print $2 }'` when I do "ssh host2 kill -USR1 $PID I get nice outputs to the screen. When I replace the first line with: dd if=image.gz | gzip -d | ssh host2 "dd of=/dev/vg1/l01 2>/tmp/output.txt" & the dd command seemd to die. I suspect a problem with the pipe, since this does work when executing locally on a host without piping. Anyone any clue on how I can redirect the dd output to a file or even better to the originating script ? thx !!! B. |
The output already comes back to the originating script - for example:
Code:
echo "abc" | ssh host2 "cat -B" 2>/tmp/error.txt Incidentally, your replacement line has /dev/vg1/l01 whereas the original had /dev/vg1/lv1. Was this a typo? |
Yes, this was a type, sorry.
Huh, this is so weird, this works right of the bat now while I'm sure I tried that before. Must have made some error somewhere ... :-s Do you think there is any way to capture this in a variable without redirecting to a file? I'm going to try and just capture the first word of the last line, because that shows the progress ... thx!!! B. |
Quote:
Code:
ERROR=$( { echo "abc" | ssh host2 "cat -B" ; } 2>&1 | tail -1 ) |
Hi Neonsignal,
thank you for that. I tried your suggestion, but that seemed to go wrong somewhere so I decided to stay with the idea of redirecting to a temporary file. That too went wrong, but that seemed to be because sometimes something goes wrong with capturing the output of dd over ssh and the relevant variable appeared empty as a result. I fixed this by examining this variable for being empty in the loop and then assigning the previous empty for it again. Since I'm checking every 5 seconds for progress on a +10 minute process, this hardly is noticed. thank again! B. |
All times are GMT -5. The time now is 07:13 AM. |