I have been scouring this site trying to find an answer to this question and came across several really good answers, unfortunately, none of them have worked for me.
Here is the script that I am using:
VALUE=`cat szpfxct.tmp`
export VALUE
echo " " >>$LGFILE
echo "term code " $VALUE >>$LGFILE
When opening the tmp file, I see a single string (201510) which should be assigned to VALUE. However, in the log file, it echo's "term code " showing that $VALUE is blank.
The permissions for the file are ok: -rw-rw-rw- 1 oracle dba 7 Oct 26 21:30 szpfxct.tmp. And the commands run fine when executed individually from the command line.
Here is the full script:
#!/usr/bin/sh
######################################
# Create Log File
######################################
LGFILE=$HOME/szpfxct_$ONE_UP.log
export LGFILE
echo "*********************************" >$LGFILE
echo "Start SZPFXCT Fix Enrollment Counts " >>$LGFILE
echo "*********************************" >>$LGFILE
echo " " >>$LGFILE
echo "starting szpfxct" `date` >> $LGFILE
echo $BANUID >>$LGFILE
echo $PSWD
echo $ONE_UP >>$LGFILE
#####################################
# Retrieve Parameter
#####################################
sqlplus $UIPW @$BANNER_LINKS/szpfxct.sql $ONE_UP 1>> $LOG 2>&1
sqlplus baninst1/[password] <<ENDsql
set echo off
set feedback off
set verify off
set timing off
set showmode off
set time off
set pagesize 60
set serveroutput on size 1000000;
clear breaks
clear computes
ttitle off
DECLARE
output_file utl_file.file_type;
term_code stvterm.stvterm_code%TYPE;
BEGIN
output_file := utl_file.fopen('/export/home/jobsub','szpfxct.tmp','w');
SELECT substr(gjbprun_value,1,6)
into term_code
from gjbprun
where gjbprun_job = 'SZPFXCT' and
gjbprun_number = '01' and
gjbprun_one_up_no = $ONE_UP;
utl_file.put_line(output_file, term_code);
utl_file.fclose_all;
END;
/
ENDsql
#TPS
chmod 777 szpfxct.tmp
VALUE=`cat szpfxct.tmp`
export VALUE
echo " " >>$LGFILE
echo "term code " $VALUE >>$LGFILE
VALUEdoes have something in it? Tryecho $VALUEright afterVALUE=`cat szpfxct.tmp`2)cat szpfxct.tmpto check the file contains data at the start of script. 3) spelling of the file maybe?