CRON TAB Instructions

Within cPanel, find the Advanced section. Select "Cron jobs", then select the Standard button to continue.

In the first text field, you should enter the email address at which you wish to recieve notices at (from the Cron job)

Then, enter the command that you wish to run at the specific interval.

Finally, select the Days, Months, Hours, and Minutes that you would like the command to run at.

Advanced use
* means every [minute,hour,day,...]
*/10 every 10th [minute,hour,day,...]
*/2 every other [minutes,hour,day,...]

To list your home dir every 5th minutes:
*/5 * * * * ls /home/username/

Common Commands used w/ Crontab

Backing up a database
mysqldump -hlocalhost -uusername -ppassword dbname > backupfilename

"Pinging" a webpage and discarding the output
curl -o /dev/null url
or
wget url > /dev/null
Retreiving a webpage (and saving the results)
curl -o filename url
or
wget url

Running a PHP script (not as a webpage)
php -q /home/username/public_html/path/filename.php > /dev/null

Emailing the output

If you want to email the output of your cron job you have several options

With shell access
crontab -e

and add

MAILTO="user@domain.com"

to the top of the crontab file.

Without shell access
Create a php script
<?php
$file = "/home/user/public_html/file.txt";
$to   = "me@example.com";
$from = "me@example.com";
$subj = "File Content";
$body = file_get_contents($file);
mail ($to, $subj, $body, "From: $from");
?>


and add this line to your cron file from NetAdmin/cPanel
php -q /home/user/public_html/phpfileyoujustcreated.php >/dev/null 2>&1

To e-mail the output of some command:
<?php

    $msg="";
    $f=fopen("php://stdin","r");  // reads standard in, actually, the output of the command, see below
    while(!feof($f))
    {
        $msg.=fread($f,4096);
    }
    fclose($f);

    $to   = "me@example.com";
    $from = "me@example.com";
    $subj = $_SERVER["argv"][1]; // the first parameter from the command line "subject_of_the_email" (0st is the PHP_SELF)
    mail ($to, $subj, $msg, "From: $from");

?>


Cron command to use:
ls /home/user/public_html/ | php -q /home/user/public_html/phpfileyoujustcreated.php subject_of_the_email

Search:


Back:
MysticServer


Category
CategorySite5
Comments [Hide comments/form]
Is there a way to do a backup of the entire reseller account, including files, databases, etc. All files, all databases in the account, not just one.

Seems crazy to have to set up 45 cron jobs for all the DBs one might have.
-- c-24-5-16-47.hsd1.ca.comcast.net (2005-04-02 12:23:11)
You could create a shell script that would loop through all your DBs and save them, as well as "tar"ing all your files. Im not a shell script wizard, but I may try to throw somethign together to at least do a full db backup.

-Jason
-- JasonR (2005-04-03 07:00:21)
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki