0

I have a linux script that gets a variable and I store it to var JOB_EXEC_ID I am trying to pass the value of this to a MySQL query

Here is MySQL query set-up

print "JOB EXEC ID value for DataMeer Job ${LOADJOB} is : ${JobExecId} " |
  tee -a ${LOGDIR}/${LOGFILE}

#Log on to MySQL to get the DataId
#Remove first the output file that would house the dataid

rm -f ${SCRDIR}/list_dataid.csv

mysql -u root -pmonday1 ${DAPDBNAME} < ${SCRDIR}/dataid_query.nosql 
SQLRTN=$?
if [[ ${SQLRTN} != 0 ]]
then
  print "Return code from sqlcall - DAP : ${SQLRTN}" |
    tee -a ${LOGDIR}/${LOGFILE}
  print "Exiting $Script - 55 " |
    tee -a ${LOGDIR}/${LOGFILE}
  exit 55
fi

The file dataid_query.nosql looks like this:

set @job_exec_id=10151
select d.id DataId
from data d inner join dap_job_configuration djc on d.dap_job_configuration__id = djc.id
left outer join dap_job_execution dje on djc.id = dje.dap_job_configuration__id and dje.created_data__id = d.id
where dje.id=@job_exec_id
into OUTFILE "/home/app1ebb/cs/list_dataid.csv"

I want to pass the value of JOB_EXEC_ID to the set command that is currently hardcoded right now with a value of 10151

Henk Langeveld
  • 8,088
  • 1
  • 43
  • 57
E B
  • 1,073
  • 3
  • 23
  • 36
  • 1
    possible duplicate of [Pass parameter to MySQL script command line](http://stackoverflow.com/questions/10229324/pass-parameter-to-mysql-script-command-line) – glenn jackman Jan 17 '14 at 20:31

1 Answers1

0

in place of

mysql -u root -pmonday1 ${DAPDBNAME} < ${SCRDIR}/dataid_query.nosql
SQLRTN=$?

this lines

sed "1 s/[0-9]*$/${JOB_EXEC_ID}/" > /tmp/dataid_query.nosql
mysql -u root -pmonday1 ${DAPDBNAME} < /tmp/dataid_query.nosql
SQLRTN=$?
rm /tmp/dataid_query.nosql
NeronLeVelu
  • 9,908
  • 1
  • 23
  • 43