Search  
   
Browse by Category
 
Netfirms 24/7 Support .: SITE: DESIGN, PUBLISHING & FTP .: G. Features Supported .: How do I create a cron job?

How do I create a cron job?

For Advantage, Business, Reseller, and Enterprise accounts, cron jobs can be configured by following these steps:
  1. Login to the Netfirms Control Panel at https://controlpanel.netfirms.com
  2. Click Hosting
  3. Choose Advanced
  4. Click Scheduled Tasks 
  5. (Optional) If you wish to receive email notifications or warning error messages regarding your cron job, enter an email address to send the notification to
  6. Enter the script name that contains the cron job. Ensure that the script name has been uploaded to the www folder of your web account
  7. Select the Time Parameters which will dictate how often the cron job will run
  8. Click Add
  9. Follow the onscreen prompts to configure your Scheduled Task
Guidelines:
(i) Enter the following Command line. For instance, to cron awstats enter: ../cgi-bin/awstats.pl -config=model -update
(ii)
Select the Time Parameters which will dictate how often you wish to have your stats updated
(i
ii) Optional: If you wish to receive email notifications or warning error messages regarding your cron job, enter an email address to send the notification

NOTE:
You can execute the script immediately to test that the cron will run properly by clicking the Run button.

IMPORTANT: If your cron job results in a "Cannot fork: Resource temporarily unavailable" error, this is likely due to too many cron jobs running simultaneously: when scheduling cron jobs, please schedule them so that they do not overlap.

A Few Examples and Guidelines:
1. To create a cron that will schedule your database backups (whereby username is the database username, password is the database password, databaseID is the database ID, backup/files/databseID.gz is the name of the compressed back up file placed inside your www folder in a subdirectory called backup/files):

mysqldump -e --force --quick -h mysqlhost -u Username -pPassword databaseID | gzip -9 >  backups/files/databaseID.gz

2. To create a cron that will schedule your database backups:

First, using Netfirms File Manager or the touch command in SSH, create a file called dbBackupFile.sql. The file may reside anywhere inside your /www folder. Then execute the following command via SSH (whereby username is the database username, password is the database password, databaseID is the database ID, backup/files/databseID.gz is the name of the .sql back up file placed inside your www folder in a subdirectory called backup/files)::

mysqldump -e --force --quick -h mysqlhost -u Username --pPassword databaseID > backup/files/databaseID.sql

3. To create a cron that will schedule your daily database backups (whereby username is the database username, password is the database password, databaseID is the database ID, backup/files/databse_20060603.gz is the name of the compressed back up file placed inside your www folder in a subdirectory called backup/files - note the date on the .gz file name will change daily):

mysqldump -u Username -pPassword databaeID | gzip > backup/files/databaseID_`date +%m_%d_%y`.gz

4. The following codes (you can name the file dbBackupFile.php in place it inside your www folder) will create a backup .sql file of your database inside your www folder:

PHP

<?php
$command = "/usr/local/nf/bin/mysqldump -hmysqlhost -uUsername -pPassword dbid > backup.sql";
exec($command,$error);
if ($error) {
echo "Error: ". $error;
}
?>

Perl/CGI

#!/usr/bin/perl
print "Content-type: text/htmlnn";
$cmd=system "/usr/local/nf/bin/mysqldump -uu70459875 -p8c2f28 d60417018 > perldbbackup.mysl";
if ($cmd)
{
print "Error!!!!";
}
else
{print "Sucess!!!!";
}

5. If you have a php v5 script that you want to cron, you should explicitly specify the php 5 path in your cron command. For instance, if /www/folder/myscipt.php needs to run as a cron, enter the following cron command:

/usr/local/nf/php5/bin/php -f ./folder/myscript.php

How helpful was this article to you?


.: Powered by Lore 1.5.6
Visit Netfirms.com Web Hosting | Copyright © 1998 - 2009 Netfirms, Inc. All Rights Reserved.