Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 739
  • Last Modified:

Pass command directly to OS

Hi...

I want to pass a command direct to the terminal.  In particular this command:

     cat /proc/cpuinfo | grep 'model name' | sed -e 's/.*: //'

and then have it displayed nice and neatly on the page.  

Currently my code looks like this:
    $cmd = "cat /proc/cpuinfo | grep 'model name' | sed -e 's/.*: //' ";
    shell_exec($cmd);

But instead of running I get an error telling me:
    Warning: shell_exec() [function.shell-exec]: Cannot execute using backquotes in Safe Mode in /var/www/web3/web/network.php on line 4

Does anyone know a way for me to get command to run? I've also tried to echo exec() and popen(), but exec gave me no errors and no output... whilst popen gave me the cryptic output "Resource id #2".

Thanks in advance.
0
Mr_Lenehan
Asked:
Mr_Lenehan
  • 4
  • 3
1 Solution
 
TeRReFCommented:
PHP runs in safe_mode. This means that there's only 1 dir that's enabled to run programs from.
Look for that dir with this command:
phpinfo();

(put it in a seperate file and run it...)
0
 
Mr_LenehanAuthor Commented:
Ran phpinfo and found the following:

Directive                       Local             Master
safe_mode                   On                     Off
safe_mode_exec_dir      no value      no value

I take it the safe mode options are configured in php.ini?
0
 
TeRReFCommented:
Yes, that's right.
The directives are already there, find them and uncomment/ define them...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Mr_LenehanAuthor Commented:
Okay, answered that bit myself. How do I restart php on unix?
0
 
TeRReFCommented:
You restart Apache, become root and type this command:
apachectl stop && apachectl start
0
 
Mr_LenehanAuthor Commented:
cheers
0
 
TeRReFCommented:
You're welcome :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now