How to set up a cron job with special characters at Hostinger

Set up a cron job with special characters like >/dev/null 2>&1 at Hostinger by creating a .sh file and scheduling it as a custom cron job.

Updated 4 weeks ago

Setting up a cron job with special characters at Hostinger, such as >/dev/null 2>&1, requires a .sh file, because the Cron Jobs section in Hostinger dashboard doesn’t accept special characters directly. First, create a .sh file containing your command in File Manager. Second, set up a custom cron job that runs the .sh file. Cron jobs without special characters can be created directly in the Cron Jobs section.

Step 1 – Create a .sh file

First, you need to create a file that will contain the command. For this, open Websites → Manage site, search for File Manager on the sidebar and click on it:

Go to the directory where you would like to store the file, for instance, the root folder of your website. If you are planning to have several cron jobs, it is recommended to create a separate folder for them.

Once in the desired patch, create a new file:

Type a name for your file, making sure to use the .sh extension, e.g. bash.sh. The new file opens in the editor.

Add the command to your .sh file. Here’s an example:

#!/bin/sh
/usr/bin/php /home/u123456789/domains/example.tld/public_html/scripts/scheduled.php > /dev/null 2>&1

Where:

  • #!/bin/sh – indicates that the cron job file is being opened

  • /usr/bin/php – loads the PHP libraries (these are required if you are executing a PHP script)

  • /home/u123456789/domains/example.tld/public_html/scripts/scheduled.php > /dev/null 2>&1 – the actual command that you want to be executed. Replace the path and filename with the actual file location and name on your hosting

When all is good to go, click Deploy in the top-right corner to make the changes live.

Step 2 – Set up a cron job

Now that the file with the command is ready, set up the cron job. Open Websites → Manage site, search for Cron Jobs on the sidebar and click on it:

Hostinger dashboard sidebar with the Cron Jobs menu item highlighted

Choose Custom, and insert your command like this:

/bin/sh /home/u123456789/domains/example.tld/public_html/scripts/bash.sh

Where:

  • /bin/sh – indicates to execute a .sh file

  • /home/u123456789/domains/example.tld/public_html/scripts/bash.sh – is the path to the actual .sh file to be executed. As this is an example, ensure to replace it with the actual path to the file corresponding to your hosting

Next, select the schedule when the Cron Job will be executed from the Common options or add it manually:

After clicking on Save, the custom cron job will be created, and your command with special characters will be executed as scheduled.

Additional resources

You can check this video tutorial or keep reading to review the process in detail: