Jump to content

Recommended Posts

Hello, Just wanted to see if someone could tell me how to execute shell commands via php

I tired with exec() and shell_exec() but it doesn't execute anything? Can someone who is familiar with this explain how this works and why it won't work when I tried.

Here is an example of what I'm trying to execute.

e.g.

 

echo shell_exec('Xvfb :2 -screen 0 1024x768x24&');

echo shell_exec('export DISPLAY=localhost:2.0');

echo shell_exec('khtml2png2 --sw 100 --sh 100 http://www.example.com example.png');

 

 

Thanks in advance!!

 

Link to comment
https://forums.phpfreaks.com/topic/186545-shell-commands-with-php/
Share on other sites

This is my current script, does anyone have any ideas of why this won't work??

Take note it runs fine from command line and produces the results needed but doesn't work from script.

 

Thanks in advance!!

 

<?php

$script1 = "Xvfb :2 -screen 0 1024x768x24&";
$script2 = "export DISPLAY=localhost:2.0";
$script3 = "khtml2png2 --sw 100 --sh 100 http://www.ask.com ask.png";

$connection = ssh2_connect('server.xxxxxxxxxxx.com', 22);
ssh2_auth_password($connection, 'root', 'xxxxxxxxxxxx');

$stream = ssh2_exec($connection, $script1);
sleep(10);
$stream = ssh2_exec($connection, $script2);
$stream = ssh2_exec($connection, $script3);
sleep(5);

fclose($stream);
echo "All done!!";
?>

run the commands in terminal first.  if they work in terminal then they will work with shell_exec()

 

Okay but the script produces a screen shot and works fine from terminal and doesn't produce the screen shot when I run it from shell_exec().

 

Any ideas of why this maybe??

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.