LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-05-2005, 09:22 AM   #1
varunbihani
Member
 
Registered: Jul 2003
Location: indore, india
Posts: 69

Rep: Reputation: 15
run shell command with php


I want to run few shell commands with PHP. I need to run lsof -i :<port_no> and kill all the process running on that port number..
I tried"
<?php
$output = shell_exec('lsof -i :8080');
print "<pre>".$output."</pre>";
?>

but it did not return any results. however the command "ps -x" return results successfully..
What could be the issue..
please help
 
Old 12-05-2005, 09:47 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Can it find the command. I don't think lsof is in the normal path and so you may need to give the whole path to the command.

graeme.
 
Old 12-05-2005, 09:53 AM   #3
varunbihani
Member
 
Registered: Jul 2003
Location: indore, india
Posts: 69

Original Poster
Rep: Reputation: 15
this is a very common command to find the processes running on particular port..
 
Old 12-05-2005, 12:44 PM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Certainly when I check on my distribution (Fedora) it is not available a normal user. Yes the command is there but not unless I give the whole path. Since php is being executed as the user of the web server that user (apache) may not be able to see the command.

graeme
 
Old 12-05-2005, 09:22 PM   #5
varunbihani
Member
 
Registered: Jul 2003
Location: indore, india
Posts: 69

Original Poster
Rep: Reputation: 15
this also did not give any ouput

I tried giving full fath .. but still not able to get output..

<?php
$output = shell_exec('/usr/sbin/lsof -i :8080');
print "<pre>".$output."</pre>";
?>
 
Old 12-06-2005, 12:25 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, this page is quite informative: http://php.planetmirror.com/manual/e...shell-exec.php .
If you redirect stdout + stderr to a temp file, you may well find the lsof exe is not avail from the shell you are creating. The relevant msg is prob written to stderr, not stdout. Hence the above suggestion about saving it to a file.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP can't execute shell command ! rome Programming 3 11-15-2005 12:46 PM
PHP can't execute shell command ! rome Programming 1 11-15-2005 09:12 AM
run shell command inside of c code? khucinx Programming 2 05-17-2004 10:04 AM
how to run shell command in java? u4u Linux - General 3 03-02-2004 09:08 AM
PHP to run Shell commands Gear_freak2000 Linux - Software 4 06-04-2003 05:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:20 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