2

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
2
  • Looks fine to me. 1) Did you check VALUE does have something in it? Try echo $VALUE right after VALUE=`cat szpfxct.tmp` 2) cat szpfxct.tmp to check the file contains data at the start of script. 3) spelling of the file maybe? Commented Oct 27, 2014 at 15:11
  • @BlueMoon I did check that and there is nothing in there. The file does contain data at the start of the script. To make things more complex, when we run this through our ERP system it runs fine, but when we run it through our cron schedule it doesn't put anything in that variable. Commented Oct 27, 2014 at 19:04

3 Answers 3

2

Try this. It will possibly give you an idea of what problem you have:

VALUE="`cat szpfxct.tmp 2>&1`"
echo "term code '$VALUE'"
term code  'cat: szpfxct.tmp: No such file or directory'

In this example, I forced the file not to exist. Also, if the variable is truly empty, you will realize it because there will be single quotes on each sides. If it is just spaces, there will be one or more spaces in between the quotes.

I suggest this because in some scripts, the stderr might have been sent somewhere where you do not see it anymore. If all there is in your script is these few lines you showed, then I can't explain why you would not have seen the stderr output. Also, what might help is to let us knwo which shell interpreter you are using. I tried sh and bash but I could not replicate your issue. That is why I am hoping this change will provide more information. If it doesn't, try this too:

VALUE="`pwd ; cat szpfxct.tmp 2>&1`"

Maybe you are not in the directory you expect to be in, and that directory also has such a file, but it's empty.

Sign up to request clarification or add additional context in comments.

2 Comments

I added the full script to the original post. I will try your approach
I put the two lines you suggested and got the same result as you show.
0

Try source your file lets say that the value of szpfxct.tmp is

VALUE=100

in your shell scriot you could do something like this

#!/usr/bin/bash
#either 
source szpfxct.tmp
#or
. .szpfxct.tmp
echo $VALUE

1 Comment

We don't have source available for use and the . .szpfxct.tmp gave a 'file not found' error. The file is available and has 777 permissions. Could be because this is running in the sh shell?
0

to source a file with sh ( bourne shell )

. /path-to-file/filename 

It should work

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.