running mysql from shell script

Reply

Join Date: Jan 2008
Posts: 6
Reputation: MONITORING is an unknown quantity at this point 
Solved Threads: 0
MONITORING MONITORING is offline Offline
Newbie Poster

running mysql from shell script

 
0
  #1
Jan 24th, 2008
Please let em know if this is valid.......

I am trying to run mysql from my shell script by passign a parameter.the sql(script.sql) is in directory $mydir and the parameter is $date and trying to run it this way:

un="username"
pd="PASSWORD "
dbname="dbname"


result = `mysql($un,$pd,$dbname,$mydir,"script.sql",$date)`

I am trying to store the date in result.is this valid statement???

Please advise???????
thanks so much!!!!!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: running mysql from shell script

 
0
  #2
Jan 25th, 2008
Hey There,

Your getting the result from the backticks is valid. I can't be sure about the mysql() function that you're referencing though. Can you post that?

Thanks,

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 6
Reputation: MONITORING is an unknown quantity at this point 
Solved Threads: 0
MONITORING MONITORING is offline Offline
Newbie Poster

Re: running mysql from shell script

 
0
  #3
Jan 25th, 2008
Hi ,

purpose of my script is that it should generate a report by running a sql script which is stored in a directory and pull the information from DB.script shld be in such a way that I just need to pass a parameter and it shld generate the report and store it in a directory in a particular format like date and time.

for example
report _ details _date__13-3-4.txt .here date is the parameter I pass.

here is the script I wrote.please let me know if valid

#!/usr/bin/ksh
un="username" # USERNAME
pd="password" # PASSWORD
dbname="dbname"

set linesize 550;
set pagesize 40;
break on report ;
set echo off

###### input box for passign the variable#####
dialog --title "Inputbox " --inputbox "Enter the date " 8 60 2>/tmp/input.txt

date=`cat /tmp/input.txt

Report(date)
Function Report(date)

#### directory where my sql script lies####
SqlDir = "C:\tmp\scripts\"
OutputDir = "C:\tmp\scripts\report\"

### directory where I want the report####
pwd=$OutputDir + '/' + $date + '/'

####running the sql script from mysql by passing the date ##
mysql($un,$pd,$dbname,$SqlDir,"script.sql",$date) >> /tmp/result.txt

####report format###
ReportFile = "report_details" + "_" + $date + "-" + `date +%d_%m_%Y` + ".txt"

mv result.txt ReportFile
Report = $OutputDir + $date + "\" + $ReportFile

End Function


Please correct me if I went wrong anywhere.
Appreciate any suggestions!!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: running mysql from shell script

 
0
  #4
Jan 28th, 2008
Hey There,

Could you post the function you're calling on this line:

mysql($un,$pd,$dbname,$SqlDir,"script.sql",$date) >> /tmp/result.txt

I'm not sure what you're actually doing to connect so I can't say if you're doing it correctly or not.

You should have a mysql() function in your script or in your environment.

Thanks

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC