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 databasemysqldump -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
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 optionsWith shell access
crontab -e
and add
MAILTO="user@domain.com"
to the top of the crontab file.
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");
?>
$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");
?>
$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
There are 2 comments on this page. [Display comments]