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

Crontab issue

Reply
  #1  
Old 07-03-09, 03:02 AM
jonnekke jonnekke is offline
Junior Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 641
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
Reply With Quote
  #2  
Old 07-03-09, 09:16 AM
End User's Avatar
End User End User is online now
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 2,833
Thanks: 13
Thanked 10 Times in 9 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 (scroll down)
Reply With Quote
  #3  
Old 07-03-09, 02:17 PM
wirehopper's Avatar
wirehopper wirehopper is offline
Community Liaison
 
Join Date: Feb 2006
Posts: 1,551
Thanks: 2
Thanked 22 Times in 22 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
Reply With Quote
  #4  
Old 07-03-09, 03:23 PM
TheDemoSite TheDemoSite is offline
Newbie Coder
 
Join Date: Sep 2004
Location: in a database!
Posts: 16
Thanks: 0
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.
Reply With Quote
  #5  
Old 07-03-09, 07:41 PM
Jcbones Jcbones is offline
Coding Addict
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 280
Thanks: 3
Thanked 5 Times in 5 Posts
or if cURL is enabled you can use...

Code:
curl --silent --compressed http://URL/to_file/not/a/file/path.php
Reply With Quote
  #6  
Old 07-04-09, 12:13 AM
wirehopper's Avatar
wirehopper wirehopper is offline
Community Liaison
 
Join Date: Feb 2006
Posts: 1,551
Thanks: 2
Thanked 22 Times in 22 Posts
... or wget ...

Code:
5 0 * * * wget http://domain.com/file.php
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

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 10:50 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 (Unregistered)