RO Users

Setup the cron job for RO Users

To be able to use RO Users a cron job must be setup so the process can run both automated and unattended. In this article we will explain how to setup a cron job in most common scenarios. Depending on your hosting environment the below instructions may not be applicable, in that case please contact your hosting provider on how to setup a cron job for your specific hosting environment.

Setup the cron job for RO Users explained

Cron command requirements

The cron command is a combination of a few settings:

  1. The PHP executable
  2. The path to cron.php
  3. The arguments

Let's take a closer look at these requirements.


PHP executable

The PHP executable is the program that processes the cron script. How the PHP executable is called completely depends on your host, check with them where your PHP executable resides. Some examples of the PHP executable are:

  • /usr/local/bin/php
  • /usr/local/bin/php56
  • /usr/local/bin/php73
  • /usr/local/bin/php74
  • /usr/local/bin/php80

Make sure to check with your host how to call the correct PHP version for your system.

Path to the cron job file

The file that processes the user accounts is called rousers.php, this file can be called directly from the command line. The file is located in /cli/rousers.php. It is important to know where the file is as you need to use the path to build the cron command. The full path needs to be the complete path to the rousers.php file. The full path depends on your host, check with them what your path needs to be. Some examples of the full path are:

  • /home/domain/public_html/cli/rousers.php
  • /www/cli/rousers.php

Arguments for the script

There are several arguments that need to be passed on to make the script work. These arguments are:

  • --username

A username of a user account that is allowed to delete users

  • --password

The password belonging to the supplied username.

  • --hostname

The URL of the website. This is used to create the opt-out link in the email sent out to users.

Build the cron command

With all the requirements in place we can build the cron command. The command is build up in this order:
PHP executable path to the rousers.php arguments

Including the arguments the full command can look like this:

/usr/local/bin/php /home/domain/public_html/cli/rousers.php --username="admin" --password="admin" --hostname="https://example.com/"

Make sure this command is all on one line. In a cron job you cannot span a command across multiple lines.

Dry run

Since RO Users 2.3.0 we have added a dry run option. This option allows you to run RO Users without actually making any changes to your system. Instead RO Users reports which steps it would take with the settings you have setup. This allows you to test your configuration without having to worry to be accidentally deleting users.

Always have a backup of your site before you first run RO Users, to be able to restore in case your settings would remove the wrong users.

The dry run option can be enabled by adding the --dryrun option to your command

/usr/local/bin/php /home/domain/public_html/cli/rousers.php --username="admin" --password="admin" --hostname="https://example.com/" --dryrun

Need help?

The cron command comes with a built-in help screen. You can get the help screen by issuing this command:

/usr/local/bin/php /home/domain/public_html/cli/rousers.php -h

Setting up the cron command

How to setup the cron command depends on your host. Check with them how to set it up for your site. There are 2 control panel systems used often, these are cPanel and DirectAdmin, instructions for these follow here.

cPanel

  1. Login to cPanel for your site
  2. Click on Cron Jobs in the Advanced area.
    RO Users cPanel advanced cron
  3. Select the time you want the job to run in the Add New Cron Job
  4. Fill in your cron command in the Command box
    RO Users cron cPanel setting
  5. Click on Add New Cron Job
  6. The job is now scheduled

DirectAdmin

  1. Login to DirectAdmin for your site
  2. Click on Cronjobs in the Advanced Features area
    RO Users Directadmin advanced cron
  3. Fill in the time you want the job to run in the Create a New Cron Job
  4. Fill in your cron command in the Command box
    RO Users cron Directadmin setting
  5. Click on Add
  6. The job is now scheduled

The output

The script will output what it has done and the output looks like this:

Starting up the magic box...
Start clearing the queue
Done clearing the queue
Start cleaning out the bounced emails
Bounce messages found: 2
Finished cleaning out the bounced emails
Start queueing users
Going to add 464 users to the queue
Done queueing users
Start processing users with no last visit date
End processing users with no last visit date
Start sending first reminders
Sending a first reminder to 5 users
Done sending first reminders
Start sending second reminders
Done sending second reminders
Start processing deletions
End processing deletions
Shutting down the magic box...