O
O
okovalev2017-12-10 03:05:34
PHP
okovalev, 2017-12-10 03:05:34

How to execute a shell command from php over ssh and return its result?

Good afternoon.
1. ssh [email protected]
2. password
3. asterisk -rv 'sip show registry'
4. Close ssh
Question: How to get the output of command 3 in php?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Saboteur, 2017-12-10
@okovalev

1. ssh [email protected]
To immediately connect to point 4 - use rsh or remsh - run one command on the remote server
rsh [email protected] "asterisk -rv 'sip show registry'"
2. password
This is not needed, configure authorization using ssh keys so that it is both safer and you do not need to enter the password manually.
3. asterisk -rv 'sip show registry'
via rsh or remsh
4. Close ssh
via rsh or remsh
Return
$result=exec("rsh [email protected] \"asterisk -rv 'sip show registry'\"") ;
print "$result"

A
Alexander X, 2017-12-10
@san-x

well, as an option,
asterisk -rv 'sip show registry' >somefile_123.txt
$output = file_get_contents('somefile_123.txt');
only it will be necessary to get confused with the unique number (123) of each call, so as not to step on your own heels.
clumsy, but for "stir up on the knee" it will do.

D
Don Gan, 2017-12-10
@PravdorubMSK

php.net/manual/en/ref.exec.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question