Current location: Hot Scripts Forums » Programming Languages » PHP » Crontab issue


Crontab issue

Reply
  #1 (permalink)  
Old 07-03-09, 03:02 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 704
Thanks: 0
Thanked 0 Times in 0 Posts
Crontab issue

Hi there..

i created a cronjob on my webserver wich calls a file named "cronjob.php".
In this file I run these lines of code:

PHP Code:

$emailsend "me@my-email-adres.com";
$subject "Test CronTab";
            
$recipient1 "someone@his-email-adres.com";
        

$headers "From: Me <$emailsend>\n";
$headers .= "X-Sender: <$emailsend>\n";
$headers .= "X-Mailer: PHP\n";
$headers .= "Return-Path: Me <$emailsend>\n";
$headers .= "MIME-Version: 1.0\n"
$headers .= "Content-type: text/html; charset=iso-8859-1\n";  
        
$message "
<html>
<head><meta content=\"MSHTML 6.00.2900.3132\" name=\"GENERATOR\"></head>
<body bgcolor=\"#ffffff\"><center>crontab testing.</center></body>
</html>"
;
                            
mail($recipient1$subject$message$headers); 
The cronjob settings are good and the "script" is running. But the PHP script
is not executed. I got these errors:

/var/www/vhosts/my-site.nl/httpdocs/cronjob.php: line 3: =: command not found
/var/www/vhosts/my-site.nl/httpdocs/cronjob.php: line 4: =: command not found
/var/www/vhosts/my-site.nl/httpdocs/cronjob.php: line 6: =: command not found
/var/www/vhosts/my-site.nl/httpdocs/cronjob.php: line 10: =: command not found
/var/www/vhosts/my-site.nl/httpdocs/cronjob.php: line 11: .=: command not found
/var/www/vhosts/my-site.nl/httpdocs/cronjob.php: line 12: .=: command not found
/var/www/vhosts/my-site.nl/httpdocs/cronjob.php: line 13: .=: command not found
/var/www/vhosts/my-site.nl/httpdocs/cronjob.php: line 14: .=: command not found
/var/www/vhosts/my-site.nl/httpdocs/cronjob.php: line 15: .=: command not found
/var/www/vhosts/my-site.nl/httpdocs/cronjob.php: line 17: =: command not found
/var/www/vhosts/my-site.nl/httpdocs/cronjob.php: line 29: syntax error near unexpected token `$recipient1,'
/var/www/vhosts/my-site.nl/httpdocs/cronjob.php: line 29: `mail($recipient1, $subject, $message, $headers);'

where did I go wrong?

_j
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-03-09, 09:16 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
I suspect you're not calling PHP to execute the file, but trying to execute it directly from cron. Show us the crontab statement that calls this file and we'll have a look. It should look something like this (with different paths and scheduling params):

10 23 * * * /usr/bin/php /path/to/cronjob.php


Notice how PHP is called and then the file to be run is specified.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-03-09, 02:17 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
You can use a 'MAILTO' in the crontab to have the output sent to a specific address.

This runs every night and tells me what files have been added or changed on my server.

Code:
MAILTO="email@domain.com"
5 0 * * * find $HOME/public_html -mtime 0
crontab(5): tables for driving cron - Linux man page
Schedule tasks on Linux using crontab
Scheduling Backup Jobs using at and crontab in debian linux crontab at files format or syntax
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-03-09, 03:23 PM
TheDemoSite TheDemoSite is offline
Newbie Coder
 
Join Date: Sep 2004
Location: in a database!
Posts: 28
Thanks: 1
Thanked 0 Times in 0 Posts
An easy and quick way to add scheduled jobs is using this:
phpJobScheduler - scheduling PHP scripts to run at set intervals your replacement for cron jobs

And there is no worrying about server application location of PHP or your user location on the server! Just add the full url to run.

you can add any number of jobs to run and it will show you the last time it ran:
phpJobScheduler - Schedule Jobs

Very useful, and its free.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-03-09, 07:41 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
or if cURL is enabled you can use...

Code:
curl --silent --compressed http://URL/to_file/not/a/file/path.php
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 07-04-09, 12:13 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
... or wget ...

Code:
5 0 * * * wget http://domain.com/file.php
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron tutorials? therocket954 PHP 4 06-26-08 07:59 AM
crontab not executing a perl script abtimoteo Perl 5 05-27-08 12:42 PM
Crontab henryw PHP 4 09-14-06 02:04 PM
Issue Tracking and Task management SlackeR Script Requests 8 10-05-05 05:29 PM
Language issue in from property, Please Help AskAR ASP 0 08-10-05 07:40 AM


All times are GMT -5. The time now is 05:13 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.