I have developed bash script to connect to database and execute .sql files. I am logging some statements in to log file using echo. While logging I am adding the date in front of the log statements which makes sense. I am unable to add date in front of output from the sqlplus and sqlldr, this is making my log to look odd and weird.
Is there a way to format (add date in front of) these outputs from sqlplus and sqlldr before writing to the log,
One issue with the sed solutions posted up to now: all output from your sqlplus command will be logged with the same time (the time the command was invoked).
This little function should log the time each line in output, which you may find much more usefull in debugging those slow SQL statements:
logoutput()
{
while read line
do
echo $(date) "$line" >> logfile
done
}
#Example usage:
sqlplus -s user/pass@Db <<EOF | logoutput
select * from asd;
select * from werw;
EOF
Edit - Another thing to be aware of is the return status of your sqlplus command will be lost (replaced with that of sed or logoutput), so ensure you don't rely on $? in the script following the sqlplus call