Best approach downloading file from mysql db

Discussion in 'Mac Programming' started by dutchchilly, Jul 15, 2010.

  1. dutchchilly macrumors member

    Jun 29, 2009
    This is my wish:

    -I want my MacMini to look (at intervals) in a mysql table to see if records with an url have been added.
    -If so, I want to run this url on the MacMini, and delete the record. As it is a .torrent file it will be downloaded to the 'download' folder, where my uTorrents will pick it up from there.

    Is this possible with AppleScript? Or should I be thinking of creating a native app in XCode?
  2. mrbash macrumors 6502

    Aug 10, 2008
    This is possible to accomplish via AppleScript. Your problem will likely be determining which entries are new/unprocessed and which are old/processed.

    But the way to do it is to do something like:

    set the_table to "files"
    set the_database to "mydatabase"
    (do shell script "/usr/local/mysql/bin/mysql -u root " & " -D " & "\\`" & the_database & "\\`" & " -e \"" & "SELECT * FROM " & "\\`" & the_table & "\\`" & "\"")
  3. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    I'd be most inclined (because I know it better) to use shell for this rather than applescript... you could wrap the shell script in an applescript if that was important. I don't know mysql's commandline parameters, but I'd imagine it would look something like:
    mysql -<user switch> <username> -<password switch> <password> -<dbname switch> <database name> -<query to run switch> "select key, url from myURLTable limit 1" > tmpFile.out
    awk -F<mysql field delimiter> '{system("curl $2 > ~/Downloads/$1.torrent; mysqlDelete $1")}' 
    Where mysqlDelete was a secondary shell script that takes a key and deletes the row from myURLTable with that key (I didn't feel like dealing with escaping in the awk system command). The curl syntax is incomplete, i just don't know off the top of my head how to download from a particular URL to a particular local file. man curl or googling for "man curl" should get you there.

  4. dutchchilly thread starter macrumors member

    Jun 29, 2009

Share This Page