If you want to create a cron job without special characters, you can set it up via hPanel directly. For cases where the cron job must include special characters, such as
>/dev/null 2>&1 in them, you will need to create a .sh file and set up a cron job to execute the file.
You can check this video tutorial or keep reading to review the process in detail:
Step 1 - Create a .sh File
First, you need to create a file that will contain the command. For this, open Websites → Manage, 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:
In the next window, enter a name for your file, making sure to use the .sh extension, e.g. bash.sh. After clicking Create, you will be directed to the file editor.
Add the command to your .sh file. Here's an example:
/usr/bin/php /home/u123456789/domains/example.tld/public_html/scripts/scheduled.php > /dev/null 2>&1
#!/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, apply the changes to your file before exiting by clicking on the save icon.
Step 2 - Set up a Cron Job
Now that the file with the command is ready, set up the Cron Job. Open Websites → Manage, search for Cron Jobs on the sidebar and click on it:
Choose Custom, and insert your command like this:
/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.