Testing an SSH Connection With PHP Through Bash
This one had been bothering me since yesterday afternoon. Apparently "php -r 'code_here'" is the way to go for calling PHP functions from a command line, rather than doing "echo 'code_here' | php". So, we now have a Bash function that calls PHP to test an SSH connection (I got tired of looking for a good way to do it entirely within Bash):
# Call as "check_ssh_root_access SERVER_NAME"
# $RES will be "HELLOWORLD" if the connection is good, "GOODBYEWORLD" otherwise
RES=`php -r "error_reporting(0);
\\$ssh_connect = ssh2_connect('$1');
if (ssh2_auth_pubkey_file(\\$ssh_connect, 'root', '/root/.ssh/id_dsa.pub', '/root/.ssh/id_dsa'))
{
echo 'HELLOWORLD';
}
else
{
echo 'GOODBYEWORLD';
}"`
Noting this in as many places as possible so I remember it next time.