| | |
running mysql from shell script
![]() |
•
•
Join Date: Jan 2008
Posts: 6
Reputation:
Solved Threads: 0
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!!!!!
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!!!!!
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
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
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!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
•
•
Join Date: Jan 2008
Posts: 6
Reputation:
Solved Threads: 0
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!!
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!!
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
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
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!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
![]() |
Similar Threads
- Linux server security guide (Network Security)
- Hotoffers get me mad !! (Viruses, Spyware and other Nasties)
Other Threads in the Shell Scripting Forum
- Previous Thread: Issue on thread_join()
- Next Thread: Rumba
| Thread Tools | Search this Thread |





