LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-07-2011, 11:47 PM   #16
AsadMoeen
Member
 
Registered: Jun 2010
Posts: 160

Original Poster
Rep: Reputation: 3

Yeah I use Swiftpanel.

And yes that would be great if you write a script for that as in that case it will do exactly what we need. So how to write a script for that ? Can you help ?
 
Old 03-08-2011, 11:02 AM   #17
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
This LQ thread may be useful regards detached screen sessions.
 
Old 03-09-2011, 12:45 AM   #18
AsadMoeen
Member
 
Registered: Jun 2010
Posts: 160

Original Poster
Rep: Reputation: 3
Hello.

The screen is no longer a problem now. I can run it easily like:

Code:
screen -A -m -S 10-srv207 ./Script.sh
This would open screen and run my script. But the problem is the terminal, it has to be logged in properly like we do it manually through putty for the user screen to work, otherwise the screen won't run.

I think Death's way maybe good.
 
Old 03-09-2011, 01:41 AM   #19
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
You tried screen's -d option?
 
Old 03-09-2011, 09:28 AM   #20
deathsfriend99
Member
 
Registered: Nov 2007
Distribution: CentOS 6
Posts: 200

Rep: Reputation: 22
Quote:
Originally Posted by AsadMoeen View Post
Yeah I use Swiftpanel.

And yes that would be great if you write a script for that as in that case it will do exactly what we need. So how to write a script for that ? Can you help ?

I shut down all my gameservers a few months back. I'll have to dig around for the script. It's not exactly what your're looking for, but I'll try to comment it enough that it can be modified. At least you'll get a good idea of what the syntax is. If you have phpmyadmin installed, it's worth poking around your mysql database to see what the names of the sql fields are. You will need them.
 
Old 03-10-2011, 12:19 AM   #21
AsadMoeen
Member
 
Registered: Jun 2010
Posts: 160

Original Poster
Rep: Reputation: 3
Yes I have it installed. Need the scripts
 
Old 03-12-2011, 12:13 PM   #22
deathsfriend99
Member
 
Registered: Nov 2007
Distribution: CentOS 6
Posts: 200

Rep: Reputation: 22
This is an example to work with. This is a code I wrote to steam update. I tried to comment it.

Code:
<?php
$id= $_GET['serverid'];
 $dbname='swift';
$link = mysql_connect('localhost', $dbname, 'yoursqldbpassword');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully <br/>';

// This could be supplied by a user, for example
//Formulate Query
// This is the best way to perform an SQL query
// For more examples, see mysql_real_escape_string()
$query = sprintf("SELECT ipid, game, query, user, password, homedir  FROM swift.server WHERE serverid='%s' ",
    mysql_real_escape_string($id));

// Perform Query
$result = mysql_query($query);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}

// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
while ($row = mysql_fetch_assoc($result)) {
  $ipid = $row['ipid'];
  $game = $row['game'];
  $valve = $row['query'];
  $user = $row['user'];
  $pass = $row['password'];
  $homdir = $row['homedir'];
}

if (!($valve == 'valve')){
  die( "Not a Steam game.<a href='JavaScript:window.close()'>Close</a>");
 } else {

  if ($game == 'Team Fortress 2'){
    $game = '"tf"';
  }
  if ($game == 'Counter-Strike 1.6'){
    $game = '"cstrike"';
  }
  if ($game == 'Counter-Strike: Source'){
    $game = '"Counter-Strike Source"';
  }
  if ($game == 'Counter-Strike: Condition Zero'){
    $game = '"czero"';
  }
  if ($game == 'Left4Dead'){
    $game = '"left4dead"';
  }
  if ($game == 'Left4Dead2'){
    $game = '"left4dead2"';
  }
   if ($game == 'Day of Defeat'){
    $game = '"dod"';
  }
  if ($game == 'Day of Defeat: Source'){
    $game = '"dods"';
  }
  if ($game == 'Garrys Mod'){
    $game = '"garrysmod"';
  }
  if ($game == 'Half Life TV'){
    $game = '"valve"';
  }
 
// Free the resources associated with the result set
// This is done automatically at the end of the script
mysql_free_result($result);

$query2 = sprintf("SELECT ip  FROM swift.ip WHERE ipid='%s' ",
    mysql_real_escape_string($ipid));

$result = mysql_query($query2);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}

// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
while ($row = mysql_fetch_assoc($result)) {
  $ip = $row['ip'];
}

mysql_free_result($result);

mysql_close($link);

// echo "<br/>";
// echo  $ipid  ;
//echo "<br/>";
// echo  $game  ;
//echo "<br/>";
// echo  $valve ;
//echo "<br/>";
// echo  $user  ;
//echo "<br/>";
// echo  $pass  ;
//echo "<br/>";
// echo  $homdir;
//echo "<br/>";
// echo  $ip    ;
 }
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($ip, 22))){
  echo "fail: unable to establish connection\n";
} else {
    // try to authenticate with username, password
  if(!ssh2_auth_password($con, $user,$pass)) {
        echo "fail: unable to authenticate\n";
    } else {
        // allright, we're in!
        echo "OK: Logged in...\n<br/><br/>";

        // execute a command
	$command0='./steam ';
	$command1='-command update ';
	$command2='-game ';
	$command3=' -dir .';
	$command= $command0. $command1. $command2. $game. $command3;
	//	echo $command ;
        if (!($stream = ssh2_exec($con,$command  ))) {
            echo "fail: unable to execute command\n";
        } else {
            // collect returning data from command
            stream_set_blocking($stream, true);
	    echo nl2br( stream_get_contents($stream));  
            //echo "Updating Steam...\n<br/><br/>";	  
//print_r($output);

// echo stream_get_line($stream,75,'...');
            echo "<br/><br/>"; 
	    
$data = "";
            while ($buf = fread($stream,4096)) 
{
                $data = $buf;
  
            }           
	    
	    fclose($stream);
        }
    }
}

echo "Done...\n";


?>
<br/>
<input name="button" type="button" onclick="window.location='serversummary.php?id=<?php echo $id; ?>
'" value="Back" />

Last edited by deathsfriend99; 03-12-2011 at 12:16 PM.
 
Old 03-12-2011, 11:57 PM   #23
AsadMoeen
Member
 
Registered: Jun 2010
Posts: 160

Original Poster
Rep: Reputation: 3
I'll try that
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 04:02 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
My Redhat Linux 9 machine won't startup but gives a startup error" njugs79 Linux - Newbie 2 03-23-2005 12:50 AM
?shell scripting startup urls? pudhiyavan Linux - General 4 01-16-2004 11:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration