Results 1 to 4 of 4

Thread: bash script

  1. #1
    Join Date
    Aug 2008
    Posts
    24

    Unanswered: 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');

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    try echoing the value of '$daily' to see whether it actually is a valid date or not
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    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

  4. #4
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •