If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > bash script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-10-08, 09:20
ammad ammad is offline
Registered User
 
Join Date: Aug 2008
Posts: 24
bash script

dear all,
i want to run bash script to delete some records by date, i wrote a script but i doesn't effect table.

Database name = uetek
tablename = stime
field = unixti

Code:
#/bin/bash
daily=`date -d "-2 days" +%Y-%m-%d`
delete from stime where unixti<=unix_timestamp('$daily');
Reply With Quote
  #2 (permalink)  
Old 09-10-08, 09:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
try echoing the value of '$daily' to see whether it actually is a valid date or not
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-12-08, 08:43
sassermann sassermann is offline
Registered User
 
Join Date: Aug 2002
Location: Germany
Posts: 17
Hi,

you pass your sql to bash which doesn't now much about it.

You should at least invoke the mysql client and pass your sql eg. by using the -e option

Andreas
Reply With Quote
  #4 (permalink)  
Old 09-12-08, 12:32
Jonathan Kinney Jonathan Kinney is offline
Registered User
 
Join Date: Aug 2008
Posts: 5
I am sure you already got this, but here is an example of what sassermann was referring to:

mysql databasename -e "delete from stime where unixti<=unix_timestamp('$daily')"

I have used that format for running MySQL commands before and it works well, though you will of course want to verify that the variables are being passed as expected, and of course that they are formatted correctly.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On