shell - How to make stderr of OS commands ran with "!" go to Sql*plus spool? -
background
i have long sql*plus script reason needs run unix commands using exclamation mark syntax.
i write spool in order have log file @ end of process.
the problem if os command fails, stderr lost , doesn't go spooled file.
example code
spool mylog.txt !echo alter user xxx identified yyyy; alter user xxx identified yyyy; !echo cp file1 folder1/ !cp file1 folder1/ !echo alter user yyy identified xxx; alter user yyy identified xxx; !echo cp file2 folder2/ !cp file2 folder2/ spool off
if 1 cp
fails, wouldn't know looking @ mylog.txt
obviously doing !cp file1 folder1/ &> mylog.txt
mess log beeing spooled in unpredictable ways.
question
what can done in order the stderr of unix commands writen file beeing spooled ?
update
i tried lc.'s suggestion, appending 2>&1
@ end of every cp command in order redirect stderr stdout this:
enter value 1:
update 2
set define off
made not prompt value. allowed me discover it's not stderr doesn't spooled: stdout doesn't either. seems everything executed "!" un-spool-able.
actually, stdout , stderr not lost won't go in spool file.
given script echo.sql
:
spool sql.out select 1 dual ; !echo 1 !invalid command spool off
if launch script shell :
sqlplus *connect string* @echo.sql > host.out 2> host.err
you output sql command in sql.out
, output echo in host.out
, error message in host.err
. if you're launching script non interactively -from cron or something- you'll have capture stdout/stderr other non sql*plus script.
edit regarding comment
with option set termout on
in script file have output of sql commands both in spool file , stdout.
so finally, if want in 1 file can call script :
sqlplus *connect string* @echo.sql &>echo.log
you still have output of sql in spool file.
Comments
Post a Comment