The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

cron Job for an SQL query

Discussion in 'General Discussion' started by tben2505, May 27, 2010.

  1. tben2505

    tben2505 Registered

    Joined:
    May 27, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Hi guys,

    I wondered if anyone could help us out. We have an SQL database running on a linux server and wish to regularly run SQL queries on it. It's basically to replace foreign characters which are somehow written to our database from the front-end forms.

    A typical SQL query we'd like to run looks something like this:

    update MainData set MD_Comment = replace(MD_Comment, '%u2013','-');

    which replaces "–" with "-" in the field "MD_Comment" in the table "MainData".

    As I understand it we can run these queries using cronjobs, which indeed we have in the past - but are now not working for some reason.

    If the database was called "database", and the username and password is "user" and "pass" for arguments sake, would someone be able to have a go at writing the cron command required in the cpanel cronjobs section?

    Many thanks for any help here, guys.

    Tom.

    PS It might be worth mentioning we'd need to run a few dozen of these queries, say once ever hour - in case that's useful to know. Cheers.
     
    #1 tben2505, May 27, 2010
    Last edited: May 27, 2010
  2. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    While I suppose you could directly redirect an SQL file into mysql on a cron schedule that is not really the best way to go about doing that.

    I would write a shell script (BASH or PHP works fine) that performs all the queries or processing that you want to do and then simply call that script via the cron at whatever timing that you wish.
     
  3. Trueliar

    Trueliar Registered

    Joined:
    May 30, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Just create a script or anything else that can interact with the server (as Spiral have already suggested) and add it as cron job.
    Pay attention to where you put that script/application and it's permissions.
     
Loading...

Share This Page