Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variable from shelle - bash to my sql script

Status
Not open for further replies.

lhg1

IS-IT--Management
Mar 29, 2005
134
DK
Hi

I need to give a variable to a mysql script from a bash shell script.

It is a date where the time is hardcoded in the script.

The Shell script
Code:
#!/bin/bash
#
####################################################
#     Script by Lars Grynderup                     #

echo "This script is used to insert a standart Weekday"
echo

[b]the_date=2007-03-30 [/b]

mysql -h localhost -u itdrift -pitdrift < weekday.sql

Paping the sql script into the connect string is a must, any other suggestions on how to do it is mutch appriciatede



The Sql script
Code:
use ah;

insert into test_table
values ("",
"Test of dates",
",
"0",
"",
date "[b]$the_date[/b] 06:00:00",
date "[b]$the_date[/b] 07:15:00"
);

The example dosn't work - and I tryede several other ways.

The only thing i need is to use the the_date variable in the sql script that I define in the shell.

Hope someone can help.

/Lhg
 
I don't know what m4 is.

But I know that i could do a sed command to change all the text in the script. But that wasn't the way I wantede to do it.

I've done something simular from unix to oracle, witch was mutch simpler.

Code:
#/bin/ksh

echo $1  


sqlplus -s test/test@oracledb <<EOF
set head off
select *
from test_table 
where filename like '$1%';
EOF


it is something like this I would like in mysql.

/Lhg

 
You could try the command line client mysql

mysql -e "select * from test_table where filename like '$1%'"

You might have to play around with " and ' and possibly escaping some characters. OK if you are just submitting a few SQL statements I was envisaging you were submitting whole jobs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top