Setting Up Cron and Windows Scheduled Tasks

Last updated April 17th, 2018

Setting Up Cron and Windows Scheduled Tasks FAQ:

How do I set up CRON on my server?

There are a few options for setting up cron jobs.

cPanel/Plesk :

  1. When you log into your cpanel/plesk you will see an option for cron jobs or scheduled tasks.
  2. Go into this and choose advanced.
  3. Set up the cron script to run every 5 minutes. The minute, hour, day of month, month, day of week fields should be filled out as:

*/5 * * * *

  1. Please copy the "Cron Command to Run" from Settings -> Cron Settings from the Email Marketer control panel into the command to run box in Plesk/cPanel.
  2. Save, and then you should see the "Last run" date updated from Settings -> Cron Settings if you refresh the page after 5 minutes.

Windows :

  1. If using a Windows webserver, you instead must use Scheduled Tasks, since Windows does not support cron natively.
  2. If you are not running your web server locally, you may have to consult your webhost.

SSH :

  1. Login to your web server via telnet or SSH.
  2. Log in to the Interspire Email Marketer control panel, go to the settings page.
  3. Copy the "Cron Command to Run" from Interspire Email Marketer into your clipboard. You can find this on the Settings -> Cron Settings page.
  4. Make sure you tick the "Yes, Cron support is enabled" option on the settings page and save your changes.
  5. Type 'crontab -e' to edit your Crontab file. This will load your Crontab into a text editor. The default text editor for Linux is Vi, so the following instructions will relate to Vi.
  6. Press 'i' to change into insert mode and add the following lines to the end of your crontab:

*/5 * * * *

Put a space after the last "*" and then press Shift+Insert on your keyboard. This will paste the "Cron Command to Run" that you copied into your clipboard earlier.

Your link should now look similiar to the following (your path to PHP and path to cron.php will most likely be different - do not copy this line!):

*/5 * * * * /usr/bin/php -f /htdocs/www/emailmarketer/admin/cron/cron.php

Save your crontab by pressing the following key sequence: escape, colon, w, q, enter

How do I set up CRON on my server using SSH?

In order to get started with cron, you must have a server that is currently running cron. Your host will also be able to tell you where you are able to setup crontabs -- whether it's from a web based control panel, or through a telnet terminal window.

Finding the necessary information

This section can be any command that can be run from a command line. In this case we are setting it up to run a script.

  • Path to PHP – UNIX and Linux have a special variable called env php which tells you where PHP is installed on your server. We'll use this instead of trying to figure out the path to PHP manually.
  • Flags for output – In this example I've used the –q flag which runs cron in quiet mode; this flag stops some unnecessary messages. You can also add /dev/null after the server path to stop error messages being output as well.
  • Server Path to your script – You will need to specify the full server path directly to your script. You can find this on the settings page, as shown below.
  • Interspire Email Marketer attempts to write the path to PHP and any flags needed as well as the path to your cron file. If this is not displayed for you there may be something on the sever that simply prohibits Interspire Email Marketer from finding this out for you. You will therefore need to find out this path yourself.

Setting up cron to run the scheduling script

Now that we know what the different parts of the command line actually do, we can begin to setup a cron job for a real use. In the system, we need to run the sendemails.php file (for sending newsletters) and the sendautos.php file (for autoresponders) in the "users" folder of the application. (Please see the documentation for exact file names as this may change with later versions of the system.)

  • Decide what frequency you wish to run the script. For every hour on the hour, you would use 0 * * * *
  • Create the cronjob. Login to telnet or your control panel and type crontab -e at the command line. This will let you edit your crontab file. Type this text in 0 * * * * env php –q /home/user1/public_html/iem/admin/cron/cron.php
  • Sit back and let cron do the rest.

How do I set up CRON on my server using Cpanel?

In order to get started with cron, you must have a server that is currently running cron. Your host will also be able to tell you where you are able to setup crontabs -- whether it's from a web based control panel, or through a telnet terminal window.

Finding your needed information

  • Path to PHP – UNIX and Linux have a special variable called env php which tells you where PHP is installed on your server. We'll use this instead of trying to figure out the path to PHP manually. If this does not work you can contact your host to find out what the correct path to PHP is.
  • Flags for output – In this example I've used the –q flag which runs cron in quiet mode; this flag stops some unnecessary messages. You can also add /dev/null after the server path to stop error messages being output as well.
  • Server Path to your script – You will need to specify the full server path directly to your script. You can find this on the settings page, as shown below.
  • Interspire Email Marketer attempts to write the path to PHP and any flags needed as well as the path to your Cron file. If this is not displayed for you there may be something on the sever that simply prohibits Interspire Email Marketer from finding this out for you. You will therefore need to find out this path yourself.

Cpanel 9 (Xskin)

Login to your control panel and look for the cronjobs icon There are two 'modes' to set cron jobs in Cpanel – you can choose either the standard or the advanced mode. The standard mode looks like this:

This is a very simple way to add the frequency of the cron without needing to know what the asterisk or the numbers mean. In the command line you then add your path to PHP and the full path to your script. In the top field, you place the email address where the output will be sent – this is usually to alert you of errors etc.

In this mode, you simply place the full command and then enter your frequency in the corresponding columns – they are clearly labeled so you can see which column are using as well.

If you add your email address to the available field you will be sent any error messages produced by cron to let you know if anything is not working as it should.

Once you have done this you just need to select 'Commit Changes' and you are done.

How do I set up scheduled tasks on a Windows server?

To set up scheduled tasks, you will need to know where PHP is installed and where Interspire Email Marketer is installed. PHP by default is installed in c:\php\bin\php.exe but your server could be different. If you are unsure of where PHP is installed, ask your administrator.

In the iem\admin\cron directory, there is a file called 'cron.php'. This is the file that you reference to schedule newsletters. You will need the full path to this file, for example: d:\www\yoursite.com\iem\admin\cron\cron.php. Note that this path will be different on your web server. If you are unsure of the path, ask your administrator.

If your host has to set up scheduled tasks for you, this will be all of the information they require. Be sure to tell them you want to run the file once an hour.

If you are setting up scheduled tasks yourself, go to the Windows Control Panel and set up a Scheduled Task as normal (you will need to Browse to locate PHP then add the path to your Interspire Email Marketer file on the end). At the end, Edit your new Scheduled Task, click the 'Schedule' tab and then click 'Advanced'.

Tick the 'Repeat Task' box and choose your settings accordingly (once an hour is quite sufficient unless you are sending a lot of emails). Click OK, then OK again and you're finished.

Congratulations, you've just setup scheduled tasks which will enable scheduled sending and autoresponders for Interspire Email Marketer as well as sending newsletters without a popup window!

Setting up Scheduled Tasks to send your emails and autoresponders

Setup Scheduled Tasks for Windows (Optional)

You might need to check with your hosting provider to see if you have access to scheduled tasks. If you don't have access, you will not be able to send autoresponders or setup scheduled sending. If you don't have access to scheduled tasks, then they might set it up for you instead.

Setting Up Scheduled Tasks

To set up scheduled tasks, you will need to know where PHP is installed and where Interspire Email Marketer is installed. PHP by default is installed in c:\php\bin\php.exe but your server could be different. If you are unsure of where PHP is installed, ask your administrator.

In the iem\admin\cron directory, there is a file called 'cron.php'. This is the file that you reference to schedule newsletters. You will need the full path to this file, for example: d:\www\yoursite.com\iem\admin\cron\cron.php. Note that this path will be different on your web server. If you are unsure of the path, ask your administrator.

If your host has to set up scheduled tasks for you, this will be all of the information they require. Be sure to tell them you want to run the file once an hour.

If you are setting up scheduled tasks yourself, go to the Windows Control Panel and set up a Scheduled Task as normal (you will need to Browse to locate PHP then add the path to your Interspire Email Marketer file on the end). At the end, Edit your new Scheduled Task, click the 'Schedule' tab and then click 'Advanced'.

Tick the 'Repeat Task' box and choose your settings accordingly (once an hour is quite sufficient unless you are sending a lot of emails). Click OK, then OK again and you're finished.

Congratulations, you've just setup scheduled tasks which will enable scheduled sending and autoresponders for Interspire Email Marketer as well as sending newsletters without a popup window!

Setting up cron on a Jumpline server

Jumpline set up their cron a little differently to most. To set this up you will need to know a few things.

Firstly, the path to your cron file can be found in the settings page of Interspire Email Marketer. If you are running Interspire Email Marketer or above Interspire Email Marketer will attempt to let you know what your complete cron command is.

(/usr/bin/php -f path/to/cron.php or something like this)

If you are not running this version Interspire Email Marketer will simply display the path to cron. If you do not see the /usr/bin/php or something like this then you will need to find this out using ssh.

To use ssh you will need an appropriate program. We use Putty here. When you use this application you will need to connect using the same details as your FTP account. This is usually your domain name for Jumpline Accounts. When you have loaded the command prompt you will then need to use your Jumpline FTP user name and password to be able to use ssh.

Once you are in you can type the command 'which php' to show you the path to PHP if you did not already know this from your Interspire Email Marketer settings page.

Next you will need to type the command:

vi /var/spool/cron/<username>

Where the user name is your ftp user name that you used as a login to ssh.

This will open up the editor vi where you need to type 'i' for Insert.

From here you will need to type the following:

*/10 * * * * /usr/bin/php -q /path/to/cron.php

If your settings page 'Path to PHP' is different to this then use that. If the command 'which php' showed a different result to '/usr/bin/php' then use that.

Basically what this is doing is saying run this command every 10 minutes, use php (and this is where you can find it), and this is the file that I want you to run.

When you have done this hit the escape key. Then hold Shift and hit Z twice. This will exit vi and save the information that you just typed.

From here type 'crontab' and if you do not receive any errors then you have done this correctly and you are ready to 'Enable Cron' in your settings page of Interspire Email Marketer.

I am running on a Windows server. Can I use Scheduled Tasks instead of CRON?

Yes you can. Simply set your scheduled task up to run the 'admin/cron/cron.php' file every 20 minutes.

You will still need to select the option 'Enable Cron' in the settings page of Interspire Email Marketer.