Jump to content

Standard question about cron jobs.


Ninjakreborn

Recommended Posts

Believe it or not for the first time in 7 years, I had to use a Cron job.  So I created a PHP script that did exactly what I wanted and put it in the root directory.  After I had that in the root directory it was time to start setting up the cron. The client is using 1and1.com and you can only do the crons for them via SSH.  So I got SSH Putty downloaded/installed and connected to the server.  Ran the crontab -e command and then went into edit mode and put in all the data needed to save the file into the cron.

'14 * * * * /kunden/usr/local/bin/php /kunden/homepages/**/****/htdocs/email_c

ron.php'

Apparently it worked and saved it correctly. I go back and do a list on the crons and it shows me that one as active.  So with all of that done, I guess it's finished.  I have a few questions.

 

1. Is there a way to test out a cron to make sure it's working, or can you pretty much guess that it's working if it's in there.  Also, what happens if I change that email_cron.php...do I need to do anything to the crontab or will it always grab that file and use it regardless..meaning I can change the file as much as I want?  Thanks again.

Link to comment
Share on other sites

I don't know if you have access to the logs with your hosting provider but normally a log entry is created in the syslog (or cron.log if you've configured it to do so).

 

And you should be able to change your file as much as you want. The crontab just "points" to it, it doesn't cache the contents anywhere so it always runs what's there when it executes.

Link to comment
Share on other sites

You can always put a [m]mail[/b] statement in your script to send an email message to yourself when the script starts (or when it finishes successfully).

 

You can also put environmental variables in the cron file so it send you email when there is a problem. Edit the cron file with "crontab -e" and add

MAILTO=your@email.address.here

to the start of the file.

 

Ken

Link to comment
Share on other sites

If your cron job typically does not produce any output, how do you know it ran?

 

I have a job that runs everyday at a set time.  If it finds a problem it sends me an email.  If there are never any problems, I would never get an email, and I would not know if everything is fine, or the cron job is just not running. So I have it check what day of the week it is.  On Friday, if it does not find any problems, it sends an email telling me it ran and everything is fine. If I don't get that email on Friday, then there is a problem with the cron job.

 

If you have multiple jobs that run at various times (daily, hourly, etc) you might consider having each job log its last completion in a table in the database.  Then add one more job that runs weekly and checks the database table. If a job did not post its log, it can send an email to let you know which one to check on.  If everything is fine, it should send an email telling you that (so you know it is running).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.