Ksh scripting issue trying to set substitution variables in a preset message lookup

I am trying to find out if I can do the following.

  1. I have a errormsg.lk file which has standard messages in it that are used in several scripts. One line in the file is
    test|testmessage ${builddate}

In my script I’m doing
message=$(grep test errormsg.lk | awk ‘BEGIN {FS = “|”} {print $2}’)

echo Error - build already in progress | mailx -s ${message} ${mailadmin}

${builddate} from the line in the lookup file is set before this this email message is created. What I am gettting is
testmessage ${builddate} but what I want is testmessage and the value of ${builddate} . Does anyone know how I can do this. It would let me create many more messages. I’ve got about 30 scripts that use this file, so you can see the benefit to having standardized messages used in all scripts.

If builddate is var then remove {} - i.e. use $builddate

That did not work.

#!/bin/ksh -p

set -x


message=$(grep test ${lookups}/errormsg.lk | awk ‘BEGIN {FS = “|”} {print $2}’)

echo message=$message

Here is the record in errormsg.lk

test|Drivers License - $builddate

Here are the results

  • lookups=/data/dl_data/drvlic/lookups
  • builddate=20150601
  • awk ‘BEGIN {FS = “|”} {print $2}’
  • grep test /data/dl_data/drvlic/lookups/errormsg.lk
  • message=‘Drivers License - $builddate’
  • echo message=Drivers License - ‘$builddate’
    message=Drivers License - $builddate

Are you sure u have in errormsg.lk
this is a var which is defined in your script but not in errormsg.lk - in errormsg.lk it is just a text

Here are the values in the file.

status|Drivers License - shows run already.
builddate|Drivers License - Directory Exists Error, already exists.
mail_recs|Drivers License - Record Counts.
download |Drivers License - FTP Error downloading files(s).
padrec|Drivers License - Padrec Error
failed|Drivers License - Spray Failed
reset |Drivers License - No Response for ESP
unknown|Drivers License - Unknown Spray Error
rename |Drivers License - Error Renaming
success|Drivers License - Completed Successfully:
test|Drivers License - $builddate

All of the values display correctly except for test. The reason that this is important for me is that in this particular set of scripts, I have 11 states where all of these messages are used. In another build I’m converting from Unix to Linux I have all 50 states and each state has both common processes and state specific processes.

I am not sure where $builddate cames from excaly but for example you can use sed in your script and to replace it with predifined string:

echo $message | sed ‘s/$builddate/’"$builddate"’/g’

Bear in mind that builddate will be a string - it has not formatting for date - if that matters…

Thanks, I will try that. The builddate is set further up in the script. Our dates are always formatted yyyymmdd. We normally get this from the file directory where the data is stored before we ftp to our local drive to work on the data. I will try the sed route, that just may work.

Then you have to use builddate=$(date) instead of builddate=20150601

I am going to have to figure something out because I can’t use $(date). This is a value that is passed in based on the directory which a file exists in. For example I might have under one state, a file per day, or 1 per month, 1 per week, or adhoc. So I have to use that date in the message.