Yes, this started out as a cPanel-specific question, but turned into a mostly Unix/Linux question. My apologies, but I appreciate the help. There are some peculiarities about cPanel cron (e.g. that it won't act on files not owned by the user), and I'm just starting to resolve them.
Cpanel really does not do anything other than just simply call the built in cron system in every Linux server and there is really nothing unusual or different about it.
Most all linux systems have two sets of crons where user cron schedules are typically stored in /var/spool/cron.
That folder contains files with the name of the user which contains the schedule for commands to run and while you could in theory execute system commands from the cron schedule directly, it is a bit messy. It is more common to write all your commands to a script file and then call that script file from your cron schedule which there should be an option on your Cpanel control panel to setup unless your hosting provider has taken that option away (often done for security purposes at many hosts).
Assuming you have access to your crontab and again the option would show up on your Cpanel, the first part of what
is written below would then allow you to setup a script that you could run from your hosting account:
For this example, your username is "dan" and you placed your commands in a script file named "myscript.sh" in your home folder,
and you want to run that script every hour at 15 minutes past the top of the hour, the following would go in your crontab using the option in your Cpanel menu (which would physically be stored on the system as "/var/spool/cron/dan"):
Code:
15 * * * * /home/dan/myscript.sh &> /dev/null
As with any Linux shell script, if you are not setting up the script or cron as the "root" user then the script you call containing your commands (myscript.sh in this example) must have executable permissions and be owned by your username.
In this example, the script file named "myscript.sh" was set to permission 750 when uploaded to /home/dan:
Code:
-rwxr-x---. 3 dan dan 496 Dec 7 2017 myscript.sh
As for what to put in the script file itself, well that is whatever commands you want to call:
Code:
#!/bin/bash
cat -- here.txt >> there.txt
echo "I am done" | mail -s "Script finished" [email protected]
(by the way, 'cat' is not really meant to copy files. If that is your purpose, use the "cp" command instead)
Another way you could do the above from cron instead of a BASH shell script is to write a PHP script and then you would be able to not only use the built in file copy commands in the PHP language but also the mail() function so your script could directly send email after calling whatever tasks you needed and not rely on the server administrator having installed "mailx".
As a PHP script via a scheduled cron call, your file generally would be setup the same and have the same rules as a normal shell script in terms of permissions and ownership of your script file except that you would call it from your crontab schedule with with either a "php" (scripts) or "GET" (urls) command call from your cron.
Cpanel fully supports setting up crontabs but is not available on all hosting accounts. In fact any hosting provider of shared hosting accounts which allows crontab to be run in itself opens up a major exploitable security hole and it is for this reason that many hosts very often disable the option it does not appear on the Cpanel on many shared web hosting accounts. If you don't have an option to setup your crontab on your control panel, you may not have crontab functions available on your hosting account at all and in that case your best option would be to use a 3rd party remote crontab service to instead call your cron script by URL.
Some hosting providers reduce the security implications by limiting crontab function to their users as something their support sets up for the users. You might need to open a support ticket at your host and ask about their policy on crontabs which it is better in shared hosting to have a host which does not allow crontabs or requires that they setup the crons for the user rather than those which openly allows all users to setup their own crontabs.
Alternatively, you could get a hosting account where you don't have other users on the same server as yourself to worry about and you have more control such as for example a dedicated server or certain classes of VPS or cloud servers where your site(s) are the only accounts active on the server but those options are generally more expensive and overkill if the single only reason at looking at those is strictly for crontab purposes alone.