Jump to content

Running cron jobs on web server


Fargone
 Share

Recommended Posts

Hello, I know this probably doesn't fit exactly into this topic but I wasn't sure where to put it. I thought maybe you guys would have some general programming knowledge that might help me. Anyways, my problem is that I'm trying to run a cronjob on my webserver and I can't tell if it's running or not. My cronjob is this: MAILTO=xyz@gmail.com* * * * * /public/scripts/cronscript.php I loaded this into the webserver using crontab and when I do crontab -l, this cronjob is displayed.Now i've read a few tutorials and from what I gather, this cronjob should be run every minute and an email sent to 'xyz@gmail.com'? This email should be sent on success and failure? The problem is I'm not getting any emails and I'm not sure if the cronjob is even running. If I'm getting no emails is the cronjob essentially not working? Thank you

Link to comment
Share on other sites

Try to actually do something in the cronscript.php file every time the file is ran... like writing to a file on your web server. It's a more reliable way of checking if things run.Also, make sure to check your spam folder. Maybe an email was sent, but you didn't saw it in your inbox, because it was considered spam.

Link to comment
Share on other sites

Yea the cronscript.php actually is another simple email program. All it does it send mail with a basic message to my account. So in theory I should be getting 2 emails each minute but.. I also wasn't sure the syntax to run the php script was right. I saw some different variations on the web so I couldn't be sure this was the right one. I just didn't even know if the cron job was running so couldn't tell if my script was right or not.

Link to comment
Share on other sites

How does cronscript.php look like?(and again, to verify if the cron job is working, make it do something on your server rather than make it send stuff)

Link to comment
Share on other sites

cronscript.php is: <?php $to = "xyz@gmail.com"; $subject = "Test Cron"; $body = "Did teh cron werk?!"; mail($to, $subject, $body);?> So I should change it to something more local? I'm still learning Php but what would be a good test script. Maybe connect to my web database and add an entry? Thanks

Link to comment
Share on other sites

or make/change a file on your webserver, like Boen is suggesting. you could make it write a formatted timestamp for example, so you could verify it's execution.http://php.net/manual/en/function.file-put-contents.php

Link to comment
Share on other sites

Ok so I tried running a simple php script in multiple ways and it didn't work. So I tried to make it simpler, and just run unix commands. I changed my cronjob to : MAILTO=xyz@gmail.com* * * * * cd /public/ && cp file1.txt fileCRON.txt From what I understand, this should change the directory to the public folder and then copy "file1.txt" to a file named "fileCRON.txt". I've loaded it and waited a few minutes. No "fileCRON.txt" file is being created. Is it safe to say that cron is indeed not running? And shouldn't I be getting an email every minute anyway? So both the fact that I'm not getting an email and that it's not working is strong evidence it's not running? I just have to go yell at the web service company and I dont want to look like an idiot ;)

Link to comment
Share on other sites

If you literally yell, you're by necessity looking like an idiot ;) .The proper approach is as you do on forums: Write the email or whatever in a way that shows you assume the problem is probably in you, but ask if maybe they've missed something on their end, and asking that they tell you what you did wrong if the problem is not on their end.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...