Jump to content


Photo

CRON JOB


  • Please log in to reply
5 replies to this topic

#1 raji20

raji20
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 25 October 2006 - 07:19 AM

I want to make the script to run automatically everyday that checks for the new emails, if any new mails are there, it need to forward to the specified address. I need this to be done via CRON JOB, how to do this, any help will be greatly appreciable.

#2 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 25 October 2006 - 07:39 AM

Firstly you'll need a script that checks the POP server for new mail and sends it to the new email address:
Documentation: http://www.php.net/imap

This is just some example code for imap:
<?php

// This gets the first email in the mailbox
$mailbox = imap_open("{localhost/pop3:110}INBOX", "#username#","#password#");
$check = imap_check($mailbox);
$new_messages = ($check->Recent ? true : false);

$index=1;

$header = imap_header($mailbox, $index);
print("<PRE>");
print("Header Date : " . $header->Date . "<BR>");
print("Header To : " . $header->to) . "<BR>";
print("Header From : " . $header->From . "<BR>");
print("Header cc : " . $header->cc . "<BR>");
print("Header ReplyTo : " . $header->ReplyTo . "<BR>");
print("Header Subject : " . $header->Subject . "<BR></PRE>");

print("<PRE>");
print(imap_body($mailbox,$index));
print("</PRE><HR>");

imap_close($mailbox);

?>

Then add this line to your cronjob:
0  12  *  10  1-7 /user/bin/php -f /location/of/scripts/to/execute.php

http://www.adminscho...ocs/crontab.htm
SA PHP Archives - www.phparchives.za.org

#3 raji20

raji20
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 25 October 2006 - 08:34 AM

First Thanks a lot for your assistance,


when i try to excute this comand from the linux server,

0    12    *    10    1-7  /usr/local/lib/php -f /www/htdocs/phpdocs/test/cron.php

it pops up the error saying

-bash: 0: command not found

Is it correct what i have done or please guide me how to add this line to CRONJOB, Im very new to this topic.






#4 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 25 October 2006 - 09:43 AM

Sorry.. my bad for not being clear.

You need to add this entry:
0     12     *     10     1-7   /usr/local/lib/php -f /www/htdocs/phpdocs/test/cron.php

into /etc/crontab
SA PHP Archives - www.phparchives.za.org

#5 raji20

raji20
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 25 October 2006 - 09:50 AM

thanks again for your assistance, when i tried this following command from the linux server

[root@place etc]# crontab 0    12    *    10    1-7  /usr/local/lib/php -f /www/htdocs/phpdocs/test/cron.php

it shows me error saying

crontab: invalid option -- f
crontab: usage error: unrecognized option

Can you please tell me about what i have did is correct or not, if it is wrong what i need to do, if it is correct how to correct this error.


#6 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 25 October 2006 - 12:09 PM

[root@place etc]# crontab 0    12    *    10    1-7  /usr/local/lib/php -f /www/htdocs/phpdocs/test/cron.php


What you need to do is edit /etc/crontab
/etc/crontab is a text file which has a collection of commands in it to execute at specific times.

So open /etc/crontab up with a text editor like so:
vi /etc/crontab

And then add this to the bottom of the file
0     12     *     10     1-7   /usr/local/lib/php -f /www/htdocs/phpdocs/test/cron.php

SA PHP Archives - www.phparchives.za.org




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users