Jump to content

returning data from an ssh2_exec()


severndigital

Recommended Posts

here's what i got.

 

$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;
		//issue the command line
		$stream = ssh2_exec($conn,$command);
		stream_set_blocking($stream,true);

		$output = ssh2_fetch_stream($stream,SSH2_STREAM_STDERR);
		echo 'what i got: ' . $output;

 

when this echo's i get.

 

what i got: Resource id #7

 

how do i turn Resource id #7 into actual information?

 

Thanks in advance,

C

Link to comment
Share on other sites

i tried that also with no luck.. just returns an empty variable.

 

when I run the .sh script in the command line on the server it returns a line of text to terminal.

 

that line of text should be outputting correct??

 


$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;

//issue the command line
$stream = ssh2_exec($conn,$command);
stream_set_blocking($stream,true);

$output = ssh2_fetch_stream($stream,SSH2_STREAM_STDERR);
$output = stream_get_contents($output);
echo 'what i got: ' . $output;

 

is that code right .. or am I missing something??

 

Thanks again,

C

Link to comment
Share on other sites

still no dice...

 

i took this code directly from the php.net page for ssh2_fetch_stream

$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, "ls");

		$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);
		$result_dio = stream_get_contents($dio_stream);

		echo 'Error gets: ' . $result_err;
		echo '<br/>';
		echo 'Dio gets: ' . $result_dio;

 

i removed my .sh script from the mix and am I just running an ls, and it comes still comes back blank.

 

another thing that interesting is that the .sh script is actually running (it does what it is supposed to on the server i am ssh'ing to) I just can't get the variable to fill with output, which is what i need) :(

Link to comment
Share on other sites

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.