Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-08-2009, 06:00 AM
|
#1
|
|
LQ Newbie
Registered: May 2009
Posts: 2
Rep:
|
trouble with file redirection in bash
Hi all, (First post, so, greetings!)
I'm having some trouble with redirection in bash.
I'm trying to redirect stderr to a file, then later redirect stderr to a different file. I thought this was just a case of (re)redirecting the filehandle 2 to the new file, but it seems I've misunderstood.
Here's a code sample showing what I'm trying to do:
###############################
####The main script (local)####
###############################
#!/bin/bash
CONNECT1="user@machine"
CONNECT2="user@machine2"
ssh $CONNECT1<<MYEND 2> ~/output-machine1
/tmp/remote-script
MYEND
ssh $CONNECT2<<MYEND 2> ~/output-machine2
/tmp/remote-script
MYEND
#######################
#### remote-script ####
#######################
#!/bin/bash
# get some output to stdout (/tmp/jaziniho does exist)
ls /tmp/jaziniho
# get some output to stderr
ls /does/not/exist
Output I get back:
to stdout:
first the list of files in /tmp/jaziniho on machine1
second the list of files in /tmp/jaziniho on machine2
for redirected stderr:
$cat output-machine1
ls: /does/not/exist: No such file or directory
However, file output-machine2 is never created, the output from stderr for the second machine is lost.
Can anyone explain what's wrong?
|
|
|
|
05-08-2009, 08:02 AM
|
#2
|
|
Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,644
|
I don't see any obvious issues so it leads me to believe you are not getting any errors on the CONNECT2. Have you done a side by side comparison of /tmp/remote-script on machine and machine2? If you accidentally left out the "ls /does/not/exist" on the latter's remote-script it might not be producing errors. (Or if you had create /does/not/exist on machine2 earlier it might be that the ls is working.)
That is to say you're assuming there is an error and perhaps there isn't one.
|
|
|
|
05-08-2009, 09:22 AM
|
#3
|
|
LQ Newbie
Registered: May 2009
Posts: 2
Original Poster
Rep:
|
*sigh*
I found a typo in my simplified test script, it actually worked in reality. (both were redirecting to output-machine1)
as for the real world version, I found a redirect to /dev/null buried deep in the heart of it.
sorry! thanks for taking the time and interest nonetheless.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:46 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|