6

How to redirect the output of below command in shell into logfile.

sqlplus -s "/nolog" <<EOF
conn / as sysdba
@?/sqlpatch/19282021/postinstall.sql
exit;
EOF

1 Answer 1

7

Just use redirection operator > at the first line:

sqlplus -s "/nolog" <<EOF >logfile
conn / as sysdba
@?/sqlpatch/19282021/postinstall.sql
exit;
EOF

You can also write >logfile at the beginning of the line, what is equally legal syntax in most shells, but less commonly practiced.

>logfile sqlplus -s "/nolog" <<EOF
conn / as sysdba
@?/sqlpatch/19282021/postinstall.sql
exit;
EOF
3
  • And you can (probably) put redirection immediately after the command word: sqlplus >logfile -s etc.
    – PM 2Ring
    Dec 12, 2014 at 13:15
  • @PM2Ring that is true, although splitting the command and its options with redirections is extremely confusing. The reason it works is that shell first assigns all redirections and only then actually starts the commands. That is also the reason why cat file >file doesn't work as expected - shell first redirect the output to file (and in the process truncate the file) and only then goes back to cat, but at this point cat reads only empty file.
    – jimmij
    Dec 12, 2014 at 13:24
  • Ah, good point. I don't find it confusing because I got used to putting redirections immediately after the command word many years ago in good old AmigaDOS, so it looks quite normal to me. :)
    – PM 2Ring
    Dec 12, 2014 at 13:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .