Jump to content

still having ssh2_exec issues


severndigital

Recommended Posts

I am trying to display the information from an ssh2_exec() call

 

here is my function right now.

 

public function checkJobBilled($jobnumber){
	echo 'Processing Job: ' . $jobnumber .'<br/>';
	$conn = ssh2_connect($this->_host);
		ssh2_auth_password($conn,$this->_user,$this->_pass)or die("Cannot Connect");
		//build command line to include this jobnumber
		$command = '/usr/local/bin/invoiced_date.sh ' . $jobnumber;
		$stdout_stream = ssh2_exec($conn, $command);

		$err_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDERR);

		$dio_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDIO);

		stream_set_blocking($err_stream, true);
		stream_set_blocking($dio_stream, true);

		$result_err = stream_get_contents($err_stream);
		echo $result_dio = stream_get_contents($dio_stream);






}

 

when i run the $command directly on the remote machine (using putty) it works and displays something like

 

jobnumber 111222 was delivered on 8/14/2009

 

to the terminal screen.

 

any reason why that is not showing up in my php code.

 

just to verify everything is working right I ran the following

 

ssh2_exec($conn,'ls -al >> "testfile.txt"');

 

when i open testfile.txt on the remote machine, it contains the ls information, so my ssh2 connection is open and working properly.

 

Any Ideas?

 

Thanks,

C

Link to comment
https://forums.phpfreaks.com/topic/179223-still-having-ssh2_exec-issues/
Share on other sites

  • 4 months later...

I was just PM'ed on this post about wether or not I found a solution.

 

well ... I did.

 

So to complete the post .. here is the answer I came up with.

 

function get_status($jobnumber)
{
	//echo 'Processing Job: ' . $jobnumber .'<br/>';
	$conn = ssh2_connect($this->_host);
	ssh2_auth_password($conn,$this->_user,$this->_pass)or die("Cannot Connect");

	//build command line to include this jobnumber
	$command = '/usr/local/bin/invoiced_date.sh ' . $jobnumber;
	$shell = ssh2_shell($conn,'xterm');
	fwrite($shell,"/usr/local/bin/invoiced_date.sh " . $jobnumber." \n ");
	usleep(350000);

	$response = fread($shell,100000);

               /// .... Parse the repsonse however you need to.

             return $response;

}

 

 

Hope others find this useful also.

 

-C

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.