LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 03-25-2010, 04:36 AM   #1
rovf
LQ Newbie
 
Registered: Feb 2010
Location: Germany
Distribution: Suse
Posts: 9

Rep: Reputation: 0
Question Redirection does not redirect


I am seeking for possible explanations under which conditions a command
prog >file
does not result in file being created. Here are the special circumstances which I observed (example simplified as much as possible):

I have a bash script ~my/script.sh which essentially contains the following commands:

#!/bin/bash --norc
~my/p1.sh >foo 2>&1
cat foo
~other/p2.sh >bar 2>&1
echo $?
cat bar
~my/p3.sh >baz 2>&1
cat baz
Several processes, running under user my, use in parallel this program in the following way:

cd ~my/Some-Directory-Unique-To-This-Process
~my/script.sh >log
This works well most of the time. Sometimes, however, we found that cat bar complains that there exists no file called bar (the echo statement always outputs 0), and indeed, foo and baz exist in these cases, but no bar. Aside from this, the file log shows no error message.

This puzzles me, because I had at least expected an empty file named bar. After all, before starting a process, bash has to do the redirection, which involves opening the output file for writing. Indeed, even a no-op statement

: >something

would create an empty file. From the fact that bar does not exist afterwards, I would conclude that either the shell could not set up the redirection (but in this case we should see some error message, don't we?), or for some reason ps.sh could not write to the file (in which case $? should not be zero). Do I miss something here? What other explanation could exist for my case?

Here some more information which might or might not be relevant:
  • The processes run partially on different hosts
  • The execution of myscript.sh takes around 5 minutes
  • Around 100 such processes are executed during one hour
  • Sometimes, the problem does not occur for weeks, but then, over a period of several hours, we see about 20% of these executions to fail in the described way
  • The problem never occurs with the redirections to the files log, foo or baz; only with bar (created from a program residing on ~other instead of ~my)
  • The home ~my is physically located on a different host than the processes running the script
  • The home ~other is also physically located on a different host, also different from the host which homes ~my

As you can see from the last two items, I vaguely suspect that networking issues could be involved. Any idea what is happening here?
 
Old 03-27-2010, 11:22 AM   #2
bobshaffer2
LQ Newbie
 
Registered: Mar 2005
Location: Ohio
Distribution: Several (Gentoo, Red Hat/Fedora, HP-UX, Helix)
Posts: 25

Rep: Reputation: 17
The *only* thing that I can imagine causing this is the shell not being able to create the file due to some kind of I/O error or the filesystem being full or something like that. Most errors are printed to stderr, so your log wouldn't have them. IIRC "$?" is the exit status of the command itself, so failure to create the file probably wouldn't affect that. IDK if that helps at all...
 
Old 03-27-2010, 12:37 PM   #3
rovf
LQ Newbie
 
Registered: Feb 2010
Location: Germany
Distribution: Suse
Posts: 9

Original Poster
Rep: Reputation: 0
Angry

Quote:
Originally Posted by bobshaffer2 View Post
The *only* thing that I can imagine causing this is the shell not being able to create the file due to some kind of I/O error or the filesystem being full or something like that. Most errors are printed to stderr, so your log wouldn't have them.
I also thought about this possibility, but then, my log would have shown the error, because for my log, I also do a 2>&1.

Another weird aspect is that the redirections of the commands before and after this specific ones ALWAYS work, and the command in question works often, but the error cases are still high enough to cause me to worry.

BTW, I meanwhile found that the command itself completed (I could see it from the side effects of the command), so the only thing missing occasionally is the redirected stdout/stderr....
 
  


Reply

Tags
bash, redirection


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirection rules for "redirect URL" identifier riteshanand40 Linux - General 1 01-20-2010 09:30 AM
Redirection gdsoccer Programming 3 05-15-2008 01:13 PM
redirection kkpal Programming 4 11-05-2007 11:24 PM
I/O redirection jittinan2 Linux - Newbie 7 08-21-2007 09:01 PM
redirection in C pantera Programming 2 08-11-2004 02:06 PM


All times are GMT -5. The time now is 05:27 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration