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



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

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"
        echo "false"

And I got this PHP script which executes script above:

$ssh = new SSH2($ssh_server, $ssh_port); 
if (!$ssh->auth($ssh_user, $ssh_password))
$ssh->exec("sh /home/...../...../za.sh");
echo $ssh->output(); 

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))
echo $ssh->exec("sh /home/...../...../za.sh");

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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