Setting up a cron job for the Snapshot add-on?
First, I want to say that I LOVE this mod and would recommend that anybody concerned about security install it post-haste. It takes all the guess work out of detecting changed/added/deleted files. Now, on to my question.
I've been trying to set it up to run as a cron job, but so far have been unsuccessful. I don't have any experience with setting up cron jobs, so I've been groping around in the dark. The cron runs, but doesn't generate anything.
PHP Version is 5.2.17
cPanel version is cPanel Pro 1.0 (RC1)
Does anybody know what would be the correct entry for setting up the cron job?
Re: Setting up a cron job for the Snapshot add-on?
Log in to your cPanel and look for the Cron Jobs icon:
Click on the image and you’ll be asked to choose your experience level click on Standard.
Creating a Cron Job
Now that you’re at the Standard Cron Manager, let’s create a cron job. You can set a job to run at a specific interval or at a specific times. Creating a cron job requires only three simple steps:
Enter your email address where it says: Please enter an email address where the cron output will be sent. Cron will send you a message when the job is executed, so you’ll know if there are any errors.
In the Command to run: field, enter the full path to your script (You will find this information in /admin/backups/snapshot/snapshot_cron.php). To run a php file, the command will begin with php.
Your path would look something like this:
/home/site162/public_html/admin/backups/snap/snapshot_cron.php
3. Now you need to set the schedule.
Set the Minute(s). You can set a short interval here, or minutes of the hour (you can select multiple items in this—and the other— boxes by using the Shift and Command keys). If you don’t care about minutes, leave this set to 0).If you want to test things, set this to run Every Five Minutes. This is a good interval for running the script, checking your email for errors, and changing settings before your inbox gets inundated with cron messages.
Set the Hour(s). If you’re creating a cron job to run RSS Import, you might want to set this to Every Hour. If you’re setting up a backup script, you might choose an hour in the middle of the night for nightly backups.
Set the Day(s). You’ll probably want to leave this set to Every Day, but you can also choose specific days of the month.
Set the Weekday(s).
Set the Month(s).
When you’ve set the schedule, your cron job is done. Click the Save Crontab button. If you set it to a short interval for testing, you should have an email with your output within a few minutes. If there’s an error (usually a problem with your path), check your settings.
Also SnapShot can be set to send and email every time SnapShots runs. So in the cron command you should use:
You can have cron send an email everytime it runs a command. If you do not want an email to be sent for an individual cron job you can redirect the command's output to /dev/null like this: mycommand >/dev/null 2>&1
When you are done the command should look like this:
This will run SnapShot ever 30min and only send a email when there was a change detected.
0,30 * * * * php /home/site162/public_html/admin/snapshot_cron.php >/dev/null 2>&1
Skip
Re: Setting up a cron job for the Snapshot add-on?
Okay, I'm an idiot. I had everything setup correctly, but I was pointing to my_admin/snapshot.php. :blush:
Thanks for the help, and thanks for a valuable mod!
Re: Setting up a cron job for the Snapshot add-on?
Okay, did a couple tests running the cron. No content in the eMail sent. Does it only generate output when there are file changes?
Re: Setting up a cron job for the Snapshot add-on?
Quote:
Originally Posted by
RescoCCC
Okay, did a couple tests running the cron. No content in the eMail sent. Does it only generate output when there are file changes?
I noticed missed stated the path of the command in last post it should be:
/home/site162/public_html/admin/backups/snapshot/snapshot_cron.php
With the cron setup as:
0,30 * * * * php /home/site162/public_html/admin/backups/snapshot/snapshot_cron.php >/dev/null 2>&1
It will run on the top of the hour and the half hour every hour of the day. (00:00 and 00:30) it will not send a notification email when it runs.
You will only get a email if SnapShot finds a file added, file deleted, file changed, folder change, folder added, folder deleted etc.
Then it is SnapShot that is sending the email not the cron.
Removing >/dev/null 2>&1 from the end of the command the cron will send a email every time it runs. And if SnapShot sees a change it will also send a email.
Skip
Re: Setting up a cron job for the Snapshot add-on?
You will find the path information that is needed for the cron in /admin/backups/snapshot/snapshot_cron.php file on line 7.
This path was created for you when SnapShot was installed.
Skip
Re: Setting up a cron job for the Snapshot add-on?
Yeah, I noticed the path error and used the correct path when setting it up. I've run some tests adding and deleting files. Running it from admin it picks them up fine, like it always has. But the cron eMail contains only:
X-Powered-By: PHP/5.2.17
Content-type: text/html
Re: Setting up a cron job for the Snapshot add-on?
HMM... I just realized that Snaphot isn't sending an eMail. It outputs the send information across the top, like this:
But no eMail arrives.
Re: Setting up a cron job for the Snapshot add-on?
Quote:
Originally Posted by
RescoCCC
HMM... I just realized that Snaphot isn't sending an eMail. It outputs the send information across the top, like this:
But no eMail arrives.
There should be no browser/screen output at all when running from the cron.
You are calling snapshot_cron.php from the cron and NOT snapshot.php?
Try this for testing:
open and edit admin/backups/snapshot/snapshot_cron.php
Code:
<?php
// Id: snapshot_cron.php v 1.3 2011/12/02
// By SkipWater <[email protected]> 12.02.2011
// This was auto created from SnapShot
// Path to this snapshot_cron.php file used for cron job
// /home/site162/public_html/admin/backups/snapshot/snapshot_cron.php
require('/home/site162/public_html/admin/includes/classes/twzFileWatch.class.php');
$snap_scan_file = '/home/site162/public_html/admin/backups/snapshot/snapshot_filewatch.txt';
$SiteName = 'Zen Carts Store Name';
$CheckFolder = '/home/site162/public_html/';
$RecurseLevel =99;
// This is who will recive the emails
// normaly the store email
$EmailTo = '[email protected]';
$fw = new twzFilewatch($SiteName, $CheckFolder, $RecurseLevel, $EmailTo);
$fw->saveFile($snap_scan_file);
// Normally SnapShot will only send an email when it detects a change
// to the files it's watching. By calling reportAlways(true),
// you can receive an email even if no changes were detected.
$fw->reportAlways(false);
$fw->minInterval('15 minutes');
// Now run it
$fw->checkFiles();
?>
change
Code:
$fw->reportAlways(false);
to
Code:
$fw->reportAlways(true);
Note: The paths will be based on your server and what you called admin.
Skip
Re: Setting up a cron job for the Snapshot add-on?
Quote:
There should be no browser/screen output at all when running from the cron.
I should have been more clear. I get the screen output when running it from admin.
Quote:
You are calling snapshot_cron.php from the cron and NOT snapshot.php?
Yes.
Changed $fw->reportAlways to true. Still no eMail when run from admin, and the cron eMail still produces only:
X-Powered-By: PHP/5.2.17
Content-type: text/html
Re: Setting up a cron job for the Snapshot add-on?
Quote:
Changed $fw->reportAlways to true. Still no eMail when run from admin, and the cron eMail still produces only:
Lets step back a little:
Running snapshot from admin will do an instant scan of your site. And not generate a email.
When running snapshot_cron it is nothing more then running snapshot with a system scheduler. The difference is snapshot_cron will not output any info to your browser/screen. Any and all info will be placed in a email and sent to you.
So if you setup the cron to run every 30min and you have set reportAlways to true in snapshot_cron.php you will get an email 10:00pm and 10:30pm etc.
If you do not get a email.
1. The email is going to a accessible email address?
2. The cron command is not setup correctly.
Try adding -q example:
0,30 * * * * php -q /home/site162/public_html/admin/backups/snapshot/snapshot_cron.php >/dev/null 2>&1
You should ask your hosting company to setup the cron for you.
Because there are tons of ways to call a php script. What I have shown you is a common cron call.
Some servers require the path to php itself.
Skip
Re: Setting up a cron job for the Snapshot add-on?
The cron runs fine, and generates an eMail notice just like it's supposed to. The problem is that the notice doesn't contain any information.
Not really a big deal, though. It would just have been gravy on the mashed potatos. The mod is still saving me a ton of time monitoring my sites.
Thanks, again for a valuable tool!