Home > dba, linux, unix > return code before grep

return code before grep

In my previous post hide-password-from-ps-output-sql-loader I mentioned a way to pass the password to the loader thru a parameter file. As correctly suggested by Brian Tkatch, the password could be passed as standard input

sqlldr control=x.ctl silent=header,feedback <<EOF
scott/tiger
EOF
Username:

The Username: prompt is displayed :(   :(

How do we get rid of this ?

sqlldr control=x.ctl silent=header,feedback <<EOF | grep -v "^Username:"
scott/tiger
EOF

There is no output. But what’s the error code

echo $?
1

The return code is 1 :(

This is not the error code from sqlldr, but the error code from grep !

Ok, here is the trick, a bit cryptic if you are not familiar with file descriptors

( ( (sqlldr control=x <<EOF;echo $? >&3) |grep -v "^Username:" >&4 ) 3>&1 |(read x;exit $x) )4>&1
scott/tiger
EOF
echo $?
0

The return code is 0 :)

Bookmark and Share

  1. Brian Tkatch
    May 15th, 2009 at 15:41 | #1

    Good post!

  2. May 15th, 2009 at 16:33 | #2

    Hi Laurent,

    You can also store the user/password in a file with 700 permissions (only the owner can read it), and pipe it directly into the sign-ons . . .

  3. May 15th, 2009 at 20:05 | #3

    Yes, that is very true, but the file may be backup up and kept in unsafe place, you never know ;-)

    Standard input is still safer as not saved to a filesystem

  1. No trackbacks yet.