Ninjakreborn Posted August 5, 2010 Share Posted August 5, 2010 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. Quote Link to comment Share on other sites More sharing options...
DWilliams Posted August 5, 2010 Share Posted August 5, 2010 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. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 5, 2010 Share Posted August 5, 2010 I've never used the shell to set a cron job, only cPanel, and in there you can set an e-mail address which will receive any output and information about the cron job when it's run. Maybe google to see if you can set that via the shell. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 5, 2010 Share Posted August 5, 2010 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 Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted August 6, 2010 Author Share Posted August 6, 2010 I appreciate that, thanks. Quote Link to comment Share on other sites More sharing options...
DavidAM Posted August 6, 2010 Share Posted August 6, 2010 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). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.