?
Solved

Sed exit status

Posted on 2004-08-19
8
Medium Priority
?
5,285 Views
Last Modified: 2013-12-26
HI All,
         this is my code template

                             sed -e s/AAA/aaa/ -e s/BBB/bbb/ -e s/CCC/cccc/ inputfile > outputfile.$$
                              RC=$?
                             if [   $RC -ne 0 ]
                             then
                                    echo "Error with exit staus $RC"
                                   
                             fi

the above shell script will run concurrently at maximum 4.Somtimes the sed returns exit status 2 and the script fails saying the error message : "Error with exit status 2"
It happens sometime and sometimes its not happening.What will be the problem??
What is that exit status 2 means in sed command.
Plz explain me
Or give me some pointers or websites to study the description of the exit status 2 in the sed command.

-Pari.
0
Comment
Question by:pari205
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 11

Expert Comment

by:cjjclifford
ID: 11842423

Hi,

try the following from the cmdline:

$ sed 's/aaa/AAA' file.that.does.not.exist
sed: can't read file.that.does.not.exist: No such file or directory
$ echo $?
2
$

So, it looks to be like occasionally the input file does not exist (try a "if [ ! -f inputfile ]; then echo File missing; fi" before the sed command). Perhaps the way the concurrency (not sure what you meant by that..) is being done some files are being listed for processing more than once, or something like that...

Cheers,
C
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 11842440
In errno.h, error 2 is:

#define ENOENT          2               /* No such file or directory */

So, apparently sed does not find the inputfile for some reason.

0
 
LVL 21

Expert Comment

by:tfewster
ID: 11847193
brett, could it be that one process opens the file for reading and it is momentarily locked to other processes? I really don't know enough about locking...

The other issue I can think of is that programs may not use errno.h, so the return codes would be whatever the programmer decided they should be...Is there a way of working out what standard include files were used?

pari205, what Unix (& version) do you use? It may be important to enable us work out where the problem lies...or at least get a definitive answer to what sed return code 2 means
0
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 23

Expert Comment

by:brettmjohnson
ID: 11848556
> brett, could it be that one process opens the file for reading and it is momentarily
> locked to other processes?  I really don't know enough about locking...

Possibly, although I would expect an error of 13 (EACCES).


> The other issue I can think of is that programs may not use errno.h, so the return codes
> would be whatever the programmer decided they should be...Is there a way of working out
> what standard include files were used?

The common unix utilities usually return error codes from errno.h for consistency.
If you are using Linux, the full source to the utilities that shipped with your distribution
should be available.  But is is not possible to determine from a shipped (stripped) executable
which header files were included during compilation.


pari205, what Unix (& version) do you use? It may be important to enable us work out where the problem lies...or at least get a definitive answer to what sed return code 2 means
0
 

Author Comment

by:pari205
ID: 11849197
But i am sure that inputfile always will be there.

But as  tfewste said "could it be that one process opens the file for reading and it is momentarily locked to other processes? I really don't know enough about locking..."

it may be the problem.But why its not showing any error like file is not ready or No such file or directory.How can i solve this problem.?Do i need to put lock on the input file.And by checking lock file,
do i have to proceed sed command.??Can u plz give me the solution.

Is there any material to study abt this kind of locking in UNIX os.

My UNix flavour is AIX Version 5

-pari


0
 
LVL 21

Expert Comment

by:tfewster
ID: 11849804
From this and your other question, I suspect that somewhere in your script the error messages are being lost; Try

sed -e s/AAA/aaa/ -e s/BBB/bbb/ -e s/CCC/cccc/ inputfile > outputfile.$$  2> errors.$$            (or 2>> all_errors.log )
0
 
LVL 5

Expert Comment

by:ITcrow
ID: 11865930

You have two problems in your code:
1. $$ doesn't always guarantee a unique filename.
2. You did not mention, how you are launching simultaneous processes.

In #2 if you are using some loop and launching it from a script, then you need to know
what's the limit on number of handles used by a process.

Check using unix commands limit / ulimit.

You can confirm the problem, by printing value of $$ and iteration of your loop.

The reason you don't always see the problem is bot #1 & #2.

Handles / Descriptors are the number of simultaneos files / process a process can launch.
0
 
LVL 22

Accepted Solution

by:
NovaDenizen earned 250 total points
ID: 11894026
The sed exit code isn't documented in the info or the man page.  I looked in the gnu sed-4.0.9 source.  sed returns an error code of 2 whenever it fails to open one of the files given it on the command line.  Gnu sed also has a 'Q' command which enables the script to return an arbitrary error code, and it is possible that the script contains a "Q 2" command.  The error code is hardcoded as 2, and the errno for failing is never used to determine the exit code, so it has no direct relationship to ENOENT.  

Sed detects failure to open the file when an fopen() call returns NULL.  fopen() fails when open() fails.  See the open() man page in section 2 to get a list of all possible causes of failure to open a file.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question