LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-03-2013, 03:54 PM   #1
Ranjith KR
LQ Newbie
 
Registered: Sep 2012
Posts: 7

Rep: Reputation: Disabled
php shell_exec not working with crontab


Hi,

I have a php script that use shell_exec for example to print the contents of crontab -l. The script works fine when i call it from terminal by php.

php test.php

But it does not work when i add it in crontab.

The script is like,

<?php
$output=shell_exec('crontab -l');
file_put_contents("testing.txt", "<pre>$output</pre>");
file_put_contents("finished.txt",'the cron has run successfully.');
?>


Crontab:
10 2 * * * /usr/bin/php /var/www/html/Ranjith/test.php > /dev/null 2>&1



Any idea?
 
Old 09-03-2013, 04:08 PM   #2
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
remember that cron runs under a limited environment. you can either put the full $PATH in your script, or in the crontab itself, or use the full path for every command.

ex: instead of just a simple cat in a script you would have to use /bin/cat or instead of ls you would have to use /bin/ls.

hope that helps.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] php shell_exec can't see system files davewithheld Linux - Server 5 08-11-2012 01:09 PM
PHP shell_exec with parameters is not working nikeshp Linux - Software 5 01-19-2012 06:51 PM
How use shell_exec funtion in php 5.2.5 over linux pinwilinux Programming 3 09-24-2009 12:51 AM
Run PHP shell_exec as root maneeshsethi Linux - General 5 12-30-2008 07:25 AM
PHP exec() and shell_exec() and SELinux Cottsay Programming 1 06-25-2005 09:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration