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 Jobs

Discussion in 'General Discussion' started by itsonlybarney, May 3, 2006.

  1. itsonlybarney

    itsonlybarney Registered

    Joined:
    May 3, 2006
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Is there a way to create a cron job that requires the deleting and creating of a database?

    I have noticed that you have to associate a user with a database. Is there a way to bypass that so that I can do the above in a PHP script??
     
  2. mctDarren

    mctDarren Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    664
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    New Jersey
    cPanel Access Level:
    Root Administrator
    (Assuming you are using MySQL)

    Don't believe so. You would still have to connect to the database via PHP using a username/password that had the proper permissions to be able to delete a database. Once you were connected it would be simple:

    Code:
    $query  = 'DROP DATABASE dbname';
    $result = mysql_query($query);
    
    But you would still need to connect first...
     
  3. hergy80

    hergy80 Well-Known Member

    Joined:
    Sep 4, 2004
    Messages:
    64
    Likes Received:
    0
    Trophy Points:
    6
    I don't know I understand your question. What do you mean by associating a user? The mysql priviledge system isn't based on your users on the system, but a database in mysql that holds user information (while cpanel does make users in mysql based on your accounts). So you can create new mysql users which are not users on your system (one methods is through phpmyadmin). Then, just set that user to have CREATE and DROP priviledges and they will be able to create or drop databases and tables. (But remember, allowing drop priviledges can allow them to drop the priviledge database as well. So don't allow this too lightly.)

    Either case, just connect to the database using php:

    Code:
    $link = mysql_connect($host, $username, $password);
    Assigning your host (usually 'localhost', and the username & password in mysql that has access to that database.

    Then to run it in a cron job, the easiest way I found is to have lynx fetch the page like someone browsing the site might:

    lynx -dump http://www.domain.com/yourscript.php

    This will then output the results to your email if you set it up to send the results to an e-mail address.

    I hope somewhere in all that answers your question.
     
  4. DalQuest

    DalQuest Member

    Joined:
    Sep 22, 2004
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    1
    Not sure what that actually means but you can create a PHP script with username and password embedded to dump and delete a database, then run it via cron. You can also do it with PERL as well as a number of other ways. Care to be more specific about what exactly you want to acomplish?

    -D-
     
Loading...

Share This Page