473,748 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

running shell_exec commands as root


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

$stringListingA llProcesses = shell_exec("lso f | 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.)
Jul 11 '08 #1
3 5880

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

$stringListingA llProcesses = shell_exec("lso f | 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
Jul 11 '08 #2
On Jul 11, 4:26 am, Erwin Moller
<Since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
LawrenceKrubner schreef:
I've a PHP script that is run as a cron job. It contains this line:
$stringListingA llProcesses = shell_exec("lso f | 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.

Jul 19 '08 #3
lawrence k schreef:
On Jul 11, 4:26 am, Erwin Moller
<Since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
>LawrenceKrubne rschreef:
>>I've a PHP script that is run as a cron job. It contains this line:
$stringListin gAllProcesses = shell_exec("lso f | 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:
$stringListingA llProcesses = shell_exec("lso f");

Also nothing???

Regards,
Erwin Moller
Jul 23 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1577
by: Sandman | last post by:
In another post I told about PHP not being able to create dates earlier than 1970, so until I can get PHP to do so, I am using a small perlscript to do it. It looks like this: // $in is something like "1943-10-12"; $unixtime = shell_exec("bin/converttime.pl $in"); Problem is, this fails once ever twenty times or so - shell_exec() doesn't return anything. This is true of another place where I use shell_exec() to run
8
6267
by: Good Man | last post by:
Hi there If I enter the following at the command line, I successfully get an email sent to the correct name/email: php /var/www/html/admin/adminscripts/welcome-cli.php 'Me' 'me@me.net'
0
6024
by: Will Seay | last post by:
At the end of this message I've pasted a script we're trying to modify slightly. I don't believe it is VBscript or javascript but these are the closest groups I could find with my limited programming knowledge. Basically, we are trying to add a few lines to this script that will execute a few shell commands (see comments at the very end of the code). We think this may be ActionScript2 but aren't sure. If you can offer any help, or know...
1
11690
by: Patrick L. Nolan | last post by:
We have a Tkinter application which has a menubar with cascade submenus. I would like to start the program with one of the submenu items state=DISABLED, then change it to state=NORMAL at a later time. I hope I just missed something obvious, because I can't figure out how to change its state. The problem comes about because the menu bar is built by several add_cascade() calls. Each of the cascades, in turn, has several add_command()...
0
1709
by: paulhjwu | last post by:
Hi, I have problems running a couple of shell scripts from PHP. I found a similar posting, so I posted my question to the original author. But unfortunately the original author is not at the address anymore. Anyone can help with the problems highlghted below?
6
5620
by: jonathan.beckett | last post by:
Hi all, We have PHP 4 installed on Windows 2003 with Apache 2, and the shell_exec has mysteriously stopped working - it hangs the page rather then returning anything. To check it out, I tried shell_exec("dir") which works fine on the development machine, but not on the live server. I'm guessing the network guys have done something to the security of
0
1337
by: Don | last post by:
Hi, I have a problem with the special characters on the function shell_exec (under Linux Debian with php 4.3.10-16): $msg = '"'."Léà t'es où?".'"'; $output = shell_exec('java myClass'.' '.$msg); All the special characters in $msg like é or à are turned into the
2
2106
by: tanyali | last post by:
I am using Linux Suse10, php 5 . execute a shell script in a terminal, it works. output is a file with data . when I use it in php like this (code : php) : chdir("../file"); $cmd="./execute-file"; shell_exec($cmd);
5
2634
by: scorpionbilli | last post by:
Hi, The local mysql server is running on my Macbook. I can access it through the console client: $ mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.0.45 MySQL Community Server (GPL)
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.