Jump to content

Shell


unidox

Recommended Posts

This is my code:

 

<?

if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22
if(!($con = ssh2_connect("localhost", 22))){
    echo "fail: unable to establish connection\n";
} else {
    // try to authenticate with username root, password secretpassword
    if(!ssh2_auth_password($con, "user", "password")) {
        echo "fail: unable to authenticate\n";
    } else {
        // allright, we're in!
        echo "okay: logged in...<br /><br />\n";
        
        function execshell ($command) {
        	global $con;
		if(!($stream = ssh2_exec($con, $command, "vt102")) ){
	        return false;
	    } else{
	        // collect returning data from command
	        stream_set_blocking( $stream, true );
	        $data = "";
	        while( $buf = fread($stream,4096) ){
	            $data .= $buf . "\n<br />";
	        }
	        return $data;
	        fclose($stream);
	    }
	}
        
        // execute a command
        if ($data = execshell("screen -X -S amitydm kill ; screen -dmS amitydm")) {
		echo $data;
	}
    }
}
?>

 

That works fine, it terminates, and creates the screen.

 

However, I need to execute the following commands in the screen:

 

cd /server/srv102/

./srcds_run -game cstrike

 

and then after those commands are run, I need the session to detach. How would I go about doing that? Thanks!

Link to comment
https://forums.phpfreaks.com/topic/170486-shell/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.