Jump to content

Recommended Posts

Hi,

 

I want to do a simple cron job to email to my self.

I have look into google and have a bit idea on it.

 

PHP version  -  >  5.2.3 - 1ubuntu 6.4

Server  API  - >  Apache 2.0 Handler

 

So I need to dl the lynx to use.

I have place it in usr/bin in the top directory. (outside then root folder).

so first time i create a cron.txt plan to stored the

 

* * * * * /usr/bin/lynx -dump http://www.example.com/tms/tmscron.php

 

(this I stored in cron.txt)

 

then I go to putty type crontab -e

 

then type the same

 

* * * * * /usr/bin/lynx -dump http://www.example.com/tms/tmscron.php

then I press ctrl+s then just close the putty.

 

But It can't run. I can't receive the email.

 

here is my tmscron.php

#!/usr/local/bin/php
<?php
$message = "Line 1 Line 2 Line 3";

$headers = 'From: xxxx@xxxxx.com' . " " .
                'Reply-To: xxx@xxxxx.com' . " " .
                'X-Mailer: PHP/' . phpversion();

mail('xxx@xxx.com', 'My Subject', $message,$headers);
?>

 

 

any step did I miss out?

Link to comment
https://forums.phpfreaks.com/topic/152351-solved-php-crontab/
Share on other sites

If your going to run some PHP script using Lynx/wget,

I dont think you need the '#!/usr/local/bin/php' at the top

 

You only need this if you want to run the script directly from the command line.

I use NANO to edit '/etc/crontab' and use WGET to run the script. The script be a normal php file that 'can' be run from your browser.

 

00 00 * * * root wget -O /dev/null http://www.somedomain.co.uk/cronjobs/daily_jobs.php /dev/null 2>&1

 

Runs daily @ 12:00am

 

This work a treat for me.

Hope it helps!

Link to comment
https://forums.phpfreaks.com/topic/152351-solved-php-crontab/#findComment-800421
Share on other sites

You do not need the /local/bin call at the top for this.

 

I would suggest running the cron through PHP CLI:

* * * * * /usr/local/bin/php -f /path/to/script/tmscron.php

 

This way you can store the cron file outside of your webroot and run it that way without anyone else being able to access it remotely and effectively spam you.

 

EDIT:

For more information on PHP CLI, see http://us3.php.net/manual/en/features.commandline.php

Link to comment
https://forums.phpfreaks.com/topic/152351-solved-php-crontab/#findComment-800436
Share on other sites

Hi,

 

thanks for the help.

the cron works. I was using putty to do that.

 

but another things was

 

how to use php script to execute the command without login to putty.

I have try

echo exec('crontab cron.txt');
echo exec('crontab -l');

 

Let say..

 

I have this original in cron.txt

* * * * *  lynx -dump  http://192.168.2.2/vstaff/tms/tmscron.php >/dev/null

 

then I edit the cron.txt to :

2 * * * *  lynx -dump  http://192.168.2.2/vstaff/tms/tmscron.php >/dev/null

then I create a php file:

<?php
echo exec('crontab -r');
echo exec('crontab cron.txt');
echo exec('crontab -l');
?>

 

It shows this in the browser

2 * * * * lynx -dump http://192.168.2.2/vstaff/tms/tmscron.php >/dev/null

 

but I login to putty go to the same directory,  and type: crontab -l

it still shows.

 

* * * * *  lynx -dump  http://192.168.2.2/vstaff/tms/tmscron.php >/dev/null

 

I need to manually use putty type: crontab cron.txt

 

then only it will change to

2 * * * * lynx -dump http://192.168.2.2/vstaff/tms/tmscron.php >/dev/null

 

How to fix that. Thanks for help.

Link to comment
https://forums.phpfreaks.com/topic/152351-solved-php-crontab/#findComment-801016
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.