Jump to content


Photo

cron jobs


  • Please log in to reply
14 replies to this topic

#1 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 27 September 2006 - 02:34 PM

i'm making a cron job in which i have to send an email subscription to numerous email addresses automatically, but the problem is cPanel's Cron Job function needs one specific email per cron job.

how can i make a cron job in which it will send a subscription to the emails saved in the database once a day?

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 27 September 2006 - 03:07 PM

Just setup a PHP script to grab the emails and process them.  Then make the cron job call that script instead of whatever you're using to mail right now.

I'm not sure if you had thought of that or not... your post is a little vague on how you're actually doing the mailing currently.

Info: PHP Manual


#3 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 27 September 2006 - 03:54 PM

i think i get what ur saying, and that's what i kinda did actually. i created php file named emailsub.php in which it gets the email list for this day and send email subscriptions to each.

my problem is how will i call that php file? can i call the cron job thru cPanel? i haven't done any cron jobs before so im kind of a newbie on the subject.

#4 Fehnris

Fehnris
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 27 September 2006 - 06:41 PM

cron jobs are 'automated' meaning that they dont need you to manually execute your php file.  You set date and time under the cron job that you want the php file to execute.  The email address you specify for the cron job is just for output of the php file.  If for instance in your case you wanted to know what email addresses were sent a subscription you could 'echo' out each email address.  The echo information or any output would be in the email sent to the address specified for the cron job.

#5 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 27 September 2006 - 06:44 PM

your CRON job command actually needs to be the command line version of what you would call if you were running it manually. so, since you're running a PHP file, your CRON job command should look something like this:

php /path/to/file/emailsub.php

now, the fun part is that some hosts have PHP installed in different locations for shared servers, so you may need to find out the path to PHP in order to call it.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#6 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 27 September 2006 - 09:21 PM

ok cool. but where should i type "php /path/to/file/emailsub.php" though?

#7 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 27 September 2006 - 10:25 PM

anyone?

#8 Fehnris

Fehnris
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 27 September 2006 - 10:30 PM

you need to have secure shell access to your webserver.  After logging in you would type crontab -e. You could then setup a cron job with the command posted my obsidian

#9 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 27 September 2006 - 10:46 PM

cool, thanks. i'll try it once my boss arrives. thanks a bunch!

#10 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 28 September 2006 - 12:41 AM

cool, thanks. i'll try it once my boss arrives. thanks a bunch!


if you're doing it from the command line, as suggested, using crontab, you'll need to set up your timing, too. for instance, if you want it to run once a day at midnight, you'd type this for your line on your crontab:

0 0 * * * php /path/to/file/emailsub.php

read up a little more on what the first 5 parameters do.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#11 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 02 October 2006 - 01:53 PM

actually, there's no mention on this page to SSL manager except in your latest post. we referred to SHELL access which would be obtained through a client such as SSH or Putty. once you have logged into your account via one of those clients and you have shell access, then you can type in crontab -e
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#12 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 02 October 2006 - 02:38 PM

You guys told me that i should type crontab -e on the SSL Manager, but where among those 3 should i type it in? Manage SSH Keys, Connect using SSHTerm, or Connect using Java Telnet Applet.?

#13 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 02 October 2006 - 04:39 PM

i do have shell access now, that's the one saying "SSH/Shell Access", right? what do i do next?

#14 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 02 October 2006 - 04:42 PM

have you logged in to your server? do you have a command prompt where you can type in shell commands? if so, just type "crontab -e" and you should be brought into your VI editor. type "i" to enter insert mode, and you can create your CRON job on your first line. once you're done, just hit "Esc" to exit insert mode and type ":wq" to save your job and exit. then, just wait for it to run. you may want to have some sort of log as part of your script to check whether or not it's actually running, though
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#15 gardan06

gardan06
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 02 October 2006 - 04:59 PM

i used Java Telnet Applet, types "crontab -e" there, and it returned a message "wrote 2 lines". im not sure if it worked though. how can i check if it did?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users