LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-01-2010, 05:58 PM   #1
bcnx
LQ Newbie
 
Registered: Aug 2010
Posts: 14

Rep: Reputation: 0
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.
 
Old 10-01-2010, 07:39 PM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
The output already comes back to the originating script - for example:
Code:
echo "abc" | ssh host2 "cat -B" 2>/tmp/error.txt
will put the "invalid option" error message into error.txt on the local machine.

Incidentally, your replacement line has /dev/vg1/l01 whereas the original had /dev/vg1/lv1. Was this a typo?
 
Old 10-02-2010, 03:37 AM   #3
bcnx
LQ Newbie
 
Registered: Aug 2010
Posts: 14

Original Poster
Rep: Reputation: 0
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.
 
Old 10-02-2010, 04:59 AM   #4
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
Originally Posted by bcnx View Post
Do you think there is any way to capture this in a variable without redirecting to a file?
Yeah, though it starts to get a bit messy, so you are perhaps better off having a temporary file than following something like this example:
Code:
ERROR=$( { echo "abc" | ssh host2 "cat -B" ; } 2>&1 | tail -1 )
This takes the pipeline in the braces, redirects all of its stdout and stderr together through tail to strip off all but the last line, and assigns it to $ERROR. You can throw away the stdout inside the braces by redirecting to /dev/null if you wanted. The semicolon is required.
 
Old 10-02-2010, 04:08 PM   #5
bcnx
LQ Newbie
 
Registered: Aug 2010
Posts: 14

Original Poster
Rep: Reputation: 0
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh and script does not redirect stderr in bakground ahk_bly Linux - Newbie 0 11-18-2008 07:02 AM
catching signals alaios Programming 3 11-16-2007 05:05 AM
catching a keypress on X MD3 Programming 0 02-14-2005 02:07 PM
Catching a Hacker... Shr00mBoXx Linux - Security 14 06-30-2004 09:59 PM
Catching first letter. TheRealDeal Linux - General 1 03-28-2004 08:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration