I have written a bash script as shown below. The script works when I run it using bash exec_proc_daily_20.sh
on the commandline. The log files are created successfully with records inside as a result of the spool $logfile
command.
#!/bin/bash
year=`date +%Y`
month=`date +%m`
day=`date +%d`
prefixe=$month$day$year
logfile="/home/oracle/logs/exec_proc_daily_20_"$prefixe.log
sqlplus / "as sysdba" <<EOF >$logfile
spool on
spool $logfile
execute Proc_RFC_MAJ_MV_ITIN;
execute Proc_RFC_MAJ_MV_REFGEO;
commit;
quit
EOF
However, when I schedule the script with crontab -e
like below:
* 4 * * * bash /home/oracle/scripts/exec_proc_daily_20.sh
The log file is created but nothing is written to it. Why isn't spool $logfile
working in this case?