chaiwei Posted April 3, 2009 Share Posted April 3, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/152351-solved-php-crontab/ Share on other sites More sharing options...
maca134 Posted April 3, 2009 Share Posted April 3, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/152351-solved-php-crontab/#findComment-800421 Share on other sites More sharing options...
premiso Posted April 3, 2009 Share Posted April 3, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/152351-solved-php-crontab/#findComment-800436 Share on other sites More sharing options...
chaiwei Posted April 4, 2009 Author Share Posted April 4, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/152351-solved-php-crontab/#findComment-801016 Share on other sites More sharing options...
chaiwei Posted April 4, 2009 Author Share Posted April 4, 2009 Hi, Any one noe how to solve this? How to make the php function exec work same as work in putty. regards, chaiwei Quote Link to comment https://forums.phpfreaks.com/topic/152351-solved-php-crontab/#findComment-801302 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.