Answer the question
In order to leave comments, you need to log in
Why bash script called from php doesn't work completely?
Hello. I'm trying to drill teeth through the same passage. Doesn't work, need help.
There is a php code that pulls a bash script on a remote server. Puff:
$connection = ssh2_connect(xxx, 22); //коннектится
if (!ssh2_auth_password($connection, 'root', 'xxx')) {
die('Не прошла аутентификация');
}
ssh2_scp_send($connection, '/path/file.sql', '/path/file.sql'); //заливает туда заранее подготовленный sql файл
$stream = ssh2_exec($connection, '/path/runner.sh'); //дергает скрипт
(the code is simplified so as not to pull the footcloth here) #!/bin/bash
ip='x.x.x.x'
user='root'
whoami
ssh -t $user@$ip ls # Для отладки. Эта команда отрабатывает нормально
ssh -t $user@$ip mysql < file.sql # А вот тут затык
echo "end" # это тоже выводится нормально
ssh $user@$ip mysql < file.sql
ssh $user@$ip 'mysql -e "select * from table"'
Answer the question
In order to leave comments, you need to log in
I have not worked with MySQL, but I assume that it uses ncurses to output to the terminal, and when you pass this file to it, it tries to output something to the console using the $TERM variable. By default it is equal to xterm-256color
. Login to your server and check if it is installed. If not, write your user under which you are executing the request in .bashrc
export TERM=xterm-256color
And try again.
How it works from PHP itself is hard to say. Maybe it's just that when you call it from the terminal, the error is ignored, and PHP receives some error code and stops working.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question