Click here to get back home

running shell_exec commands as root

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
running shell_exec commands as root Lawrence Krubner 07-11-2008
Posted by Lawrence Krubner on July 11, 2008, 4:06 am
Please log in for more thread options

I've a PHP script that is run as a cron job. It contains this line:

$stringListingAllProcesses = shell_exec("lsof | grep vsftpd");


The lsof command returns almost nothing unless you are the root user.
Can anyone think of a way I can use su or sudo or something else to get
this script to run as root?

(And yes, I'm aware that it is dangerous to allow a PHP script to run as
root, but it is in an otherwise secure environment, far removed from the
web.)



Posted by Erwin Moller on July 11, 2008, 4:26 am
Please log in for more thread options

Lawrence Krubner schreef:
>
> I've a PHP script that is run as a cron job. It contains this line:
>
> $stringListingAllProcesses = shell_exec("lsof | grep vsftpd");
>
>
> The lsof command returns almost nothing unless you are the root user.
> Can anyone think of a way I can use su or sudo or something else to get
> this script to run as root?
>
> (And yes, I'm aware that it is dangerous to allow a PHP script to run as
> root, but it is in an otherwise secure environment, far removed from the
> web.)

Hi,

The easiest way is to make a cronjob for root.
Just go root and crontab it.

If you have no rootaccess, you cannot run as root of course....

Regards,
Erwin Moller

Posted by lawrence k on July 18, 2008, 8:56 pm
Please log in for more thread options
On Jul 11, 4:26 am, Erwin Moller
> LawrenceKrubnerschreef:
>
>
>
> > I've a PHP script that is run as a cron job. It contains this line:
>
> > $stringListingAllProcesses = shell_exec("lsof | grep vsftpd");
>
> > The lsof command returns almost nothing unless you are the root user.
> > Can anyone think of a way I can use su or sudo or something else to get
> > this script to run as root?
>
> > (And yes, I'm aware that it is dangerous to allow a PHP script to run as
> > root, but it is in an otherwise secure environment, far removed from the
> > web.)
>
> Hi,
>
> The easiest way is to make a cronjob for root.
> Just go root and crontab it.
>
> If you have no rootaccess, you cannot run as root of course....


That is what I tried first. I logged in as root and did "crontab -e".
But the script doesn't seem to run as root. The lsof in the script
seems to run as... I don't know who. It returns no data, which would
make sense for a non-root user.




Posted by Erwin Moller on July 23, 2008, 1:11 pm
Please log in for more thread options
lawrence k schreef:
> On Jul 11, 4:26 am, Erwin Moller
>> LawrenceKrubnerschreef:
>>
>>
>>
>>> I've a PHP script that is run as a cron job. It contains this line:
>>> $stringListingAllProcesses = shell_exec("lsof | grep vsftpd");
>>> The lsof command returns almost nothing unless you are the root user.
>>> Can anyone think of a way I can use su or sudo or something else to get
>>> this script to run as root?
>>> (And yes, I'm aware that it is dangerous to allow a PHP script to run as
>>> root, but it is in an otherwise secure environment, far removed from the
>>> web.)
>> Hi,
>>
>> The easiest way is to make a cronjob for root.
>> Just go root and crontab it.
>>
>> If you have no rootaccess, you cannot run as root of course....
>
>
> That is what I tried first. I logged in as root and did "crontab -e".
> But the script doesn't seem to run as root. The lsof in the script
> seems to run as... I don't know who. It returns no data, which would
> make sense for a non-root user.
>

Hi,

Roor user should be able to run that command just fine.
Are you sure you simply don't have a process named 'vsftpd'?
What does this produce:
$stringListingAllProcesses = shell_exec("lsof");

Also nothing???

Regards,
Erwin Moller

Similar ThreadsPosted
running exec as root? January 12, 2005, 2:18 pm
AT Commands June 1, 2007, 5:24 am
Multiple commands July 14, 2004, 3:48 pm
fsockopen commands August 1, 2006, 3:39 pm
How to execute two commands within 'system' February 14, 2006, 11:47 am
Some commands execute via PHP "system", some don't--why? November 18, 2006, 11:26 am
Commands out of sync error January 16, 2008, 12:18 am
having problems with mySQL commands March 22, 2008, 9:54 am
why is system() so slow for remote commands? August 30, 2004, 11:37 pm
Converting from MySQL commands to Oracle: HELP! December 2, 2004, 1:06 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap