Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is it possible to execute terminal commands using PHP? I need to display cores alloted to each VM and some other details of the virtual machine. Am using KVM. can anyone help to do so. Am using Ubuntu server 11.04. Can anyone explain with example.

share|improve this question
    
refer stackoverflow.com/questions/10598561/… –  saji89 Oct 8 '12 at 8:20
    
there is no clear idea on that –  Poorni Ma Oct 8 '12 at 8:48
    
Are you looking for exact method to solve your KVM issue or the way to run terminal commands from PHP? –  saji89 Oct 8 '12 at 8:51
    
@saji89 i need to know how to run terminal commands in php. is there any other way to make link with KVM virtual manager by php coding ??? –  Poorni Ma Oct 8 '12 at 8:55
add comment

1 Answer

you can use back-ticks, exec or system command to run terminal commands.

Here is the sample script which might help you

<?php

# back-ticks
$cpuinfo1=`lscpu`;
echo $cpuinfo1;
echo "\n===================\n";

#exec
echo "\n nproc details are here " . exec('nproc');
echo "\n===================\n";

#system
$cpuinfo2 = system('cat /proc/cpuinfo');
echo $cpuinfo2;

?>
share|improve this answer
    
sorry it doesn't works. It displays "===================nproc details are here =================== " –  Poorni Ma Oct 8 '12 at 9:25
    
Do you get any error? –  devav2 Oct 8 '12 at 9:28
    
It displays "===================nproc details are here =================== " –  Poorni Ma Oct 8 '12 at 9:29
    
Do you get any results when you open a terminal and run nproc? –  devav2 Oct 8 '12 at 9:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.