I've got a web-server with my hardcoded webpanel for Source server management and I've got my VPS on CentOS which doesn't really want to execute sh script when asked from remote server.

Web-server and CentOS Server are not on a same server!!!

I got this SH script:

#! /bin/bash

SERVER_PORT="xxxx"
SERVER_IP="xxxx"
SERVER_MP="xxxx"
SERVER_MAP="xxxx"
SERVER_GAME="xxxx"

# CODE

OLDID=`cat pid_file 2> /dev/null`
if [ "$OLDID" != "" ]; then
    screen -X -S $OLDID quit
    rm -f pid_file
    sleep 1
fi

if [ "$1" != "stop" ]; then
    PORT_CHECK=`netstat -tuln | grep $SERVER_PORT`
    if [ "$PORT_CHECK" == "" ]; then
        UNIQID=`date +%Y%M%d%H%M%S`
        echo $UNIQID > pid_file
        screen -A -m -d -S $UNIQID ./srcds_run -console -game $SERVER_GAME -ip $SERVER_IP -port $SERVER_PORT -maxplayers $SERVER_MP +map $SERVER_MAP
        echo "true"
    else
        echo "false"
    fi
fi

And I got this PHP script which executes script above:

include('classes/ssh.class.php');
$ssh = new SSH2($ssh_server, $ssh_port); 
if (!$ssh->auth($ssh_user, $ssh_password))
die('nologin');
$ssh->exec("sh /home/...../...../za.sh");
echo $ssh->output(); 
die();

This is what I get on $ssh->output()

No screen session found. true

When script is executing pid_file is not being created, server does not start and nothing exactly works but this silly warning.

What am I doing wrong?

UPD: When I execute this script via SSH console (Putty) everything works: file is being created and server starts in screen session. When I execute the same script via PHP ssh class it doesn't work properly.

UPD2: Both Putty and PHP script are logging in to system as non-root user. The game server has no need in running as root.

  • Sounds like a user account-related problem. What user is PHP running as? Can that user execute these commands? – gronostaj Oct 16 '14 at 19:54
  • >Web-server and CentOS Server are not on a same server!!! I mean that web-server and my VPS are separate. I use hosting provider for my web sites and use my VPS for game servers. If you mean which user does PHP use for logging in — non root user, but the directory and server executable (srcds thing) got sufficient permissions for running via this user. – Артём Doe Oct 16 '14 at 19:55

Try this (using phpseclib, a pure PHP SSH implementation):

$ssh = new Net_SSH2($ssh_server, $ssh_port);
if (!$ssh->login($ssh_user, $ssh_password))
die('nologin');
//$ssh->enablePTY();
echo $ssh->exec("sh /home/...../...../za.sh");
die();

If that doesn't work for you try uncommenting out the $ssh->enablePTY()

  • Why do you believe that this will solve the problem? – G-Man Oct 16 '14 at 21:25
  • Tried and still not working. – Артём Doe Oct 17 '14 at 6:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.