Using 2>&1

rm -f $runLog

sqlplus $CONNECT_STRING @$sql_filename $cycle_controlcsv > $runLog 2>&1

rc=$?

pls tell me what above code does ,

Thanks .

In a nutshell: It talks to the Oracle DB and redirects all output to a logfile.

# delete logfile
rm -f $runLog

# connect to Oracle database
sqlplus $CONNECT_STRING @$sql_filename $cycle_controlcsv > $runLog 2>&1

# assign exit status/return code of the previous command to the rc variable
rc=$?

sqlplus : command line interface
$CONNECT_STRING : self-explaining, something like user/password@server:port/instance
@$sql_filename : execute SQL statements from the script in $sql_filename
$cycle_controlcsv : most likely arguments passed to parameters (&1, &2,...)
> $runLog : redirect standard output (stdout) to a logfile
2>&1 : redirect standard error to standard output, or the same logfile respectively

1 Like