5

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
6

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
|improve this answer|||||
  • And you can (probably) put redirection immediately after the command word: sqlplus >logfile -s etc. – PM 2Ring Dec 12 '14 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 '14 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 '14 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.