LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-21-2015, 01:36 AM   #1
sleftar
Member
 
Registered: Sep 2015
Posts: 51

Rep: Reputation: Disabled
Sending command to screen shell script


Hi guys, I have a game server running on ubuntu 14.. So there are 2 servers for the specific game and each of them is kept in different screens such as:

Quote:
screen -ls
There are screens on:
1663.cave (21/10/15 02:20:21) (Detached)
1657.world (21/10/15 02:20:20) (Detached)
2 Sockets in /var/run/screen/S-gingercook.
If you turn back to each screen it opens a remote console for each specific server and from there you can enter commands that is specific to the game such as banning people, killing etc..

These game commands are too long and i want to simplify it. For example when i select a player instead of the command

c_select(AllPlayers[4])

I want to simplify it as

p'4'

so linux would send c_select(AllPlayers[4]) to the game console.. Is it possible to do such a thing.. i have some idea about shell scripting, it is kind of a real beginner but i know basic statements and such.

Any help would be appreciated...

Thank you very much in advance...
 
Old 10-21-2015, 07:35 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Depends how much you wish to stretch that.

You could create a program named p

And then accept arguments so that you could use 1, 2, 3, 4, A, or other stuff. But the syntax would not match what you show.

Further, you could create an alias. You can try that manually in the command line and when you get it right you can insert it into a profile file, like .bashrc in your home directory.

Also the same issue is that the syntax would not be exactly as you've envisioned:
Code:
$ alias p4=c_select\(AllPlayers[4]\)
Would work, but putting the single quotes or even other things like parentheses around the 4 in the first term gets rejected, even if I try to escape it using \. Type 'alias' to see what aliases you do have defined and once you successfully create one you can type the left side to validate that you got it working properly.
 
Old 10-21-2015, 07:42 AM   #3
slacksam
Member
 
Registered: Oct 2012
Location: Germany
Distribution: Slackware, Salix, slarm64
Posts: 210

Rep: Reputation: 37
You could use ssh to send the commands remotely.

Is a ssh server running on the server machines?

If so, you would want to add public ssh keys from your machine to the authorized_keys file on the server, so you don't need to enter the passwords when connecting to the server.
Further you could create aliases for the remote machines in the .ssh/config file on your machine, to have easy access to the servers.
Then you could use "ssh <alias_to_server> <command_to_execute>" to send the commands from your machine to the servers.
For these commands you can then generate aliases or use a shell script.
 
Old 10-21-2015, 10:21 AM   #4
sleftar
Member
 
Registered: Sep 2015
Posts: 51

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
Depends how much you wish to stretch that.

You could create a program named p

And then accept arguments so that you could use 1, 2, 3, 4, A, or other stuff. But the syntax would not match what you show.

Further, you could create an alias. You can try that manually in the command line and when you get it right you can insert it into a profile file, like .bashrc in your home directory.

Also the same issue is that the syntax would not be exactly as you've envisioned:
Code:
$ alias p4=c_select\(AllPlayers[4]\)
Would work, but putting the single quotes or even other things like parentheses around the 4 in the first term gets rejected, even if I try to escape it using \. Type 'alias' to see what aliases you do have defined and once you successfully create one you can type the left side to validate that you got it working properly.
Thank you very much.. But the problem is, since game console in screen is a different environment, so I should enter this p4 into the game console and then linux should take this command and replace it with c_select(AllPlayers[4])

Last edited by sleftar; 10-21-2015 at 10:44 AM.
 
Old 10-21-2015, 11:03 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
What game server are you running?

Is the game console a regular terminal window or part of the game? By regular terminal window are you entering the command like:
[user@server:~]$ game c_select(AllPlayers[4])

If the console is actually the game then an alias or other terminal shortcut as far as I know is not going to work. That would require you to change the game source code.
 
Old 10-21-2015, 11:27 AM   #6
sleftar
Member
 
Registered: Sep 2015
Posts: 51

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
What game server are you running?

Is the game console a regular terminal window or part of the game? By regular terminal window are you entering the command like:
[user@server:~]$ game c_select(AllPlayers[4])

If the console is actually the game then an alias or other terminal shortcut as far as I know is not going to work. That would require you to change the game source code.
It is don't starve together.. And you don't enter commands to terminal. So console is the game console where all logs can be seen and such...

The remote console is something like this.

Quote:
0032
[SHARD] CLOSE CONNECTION for 2752831393
CloseConnectionWithReason: ID_DST_SHARD_SILENT_DISCONNECT
[Steam] UserDisconnect successfully sent for steamid '76561198102297818'
[SHARD] Received disconnect notification for 'KU_ZnDkO0Ka' on server '[SHDMASTER](1)' ('[SHDMASTER](1)')
[SHARD] Migration of player 'KU_ZnDkO0Ka' to 'caves(485967294)' (14) succeeded
[SHARD] Writing save location file for 'KU_ZnDkO0Ka'
[SHARD] Save location file written! /home/gingercook/.klei/DoNotStarveTogether/save/session/FFFFFFFF896B1359/KU_ZnDkO0Ka_/savelocation
c_listallplayers''
ConsoleInput: "c_listallplayers''"
[1] BluAngel <wilson>
[2] paul <woodie>
[3] Fabioty <wx78>
[4] Ghostmin <willow>
[5] klik2001 <wathgrithr>
where c_listallplayers''
is a console input that i entered. Basically it is a different environment.. Not terminal. It is a program that you download from steamcmd so it has its very own console like any other game server on steamcmd. Then the only way is to change source code?

Last edited by sleftar; 10-21-2015 at 11:37 AM.
 
Old 10-21-2015, 11:37 AM   #7
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 509

Rep: Reputation: 203Reputation: 203Reputation: 203
Hi there,

Instead of attaching to the screen session and then typing the command, you might consider sending commands to the screen session remotely from your shell (detached from screen).

The command to do this would look something like this:

Code:
screen -S cave -p 1 -X stuff "c_select(AllPlayers[4])^M"
Where "-p 1" is the screen window number in which your game console is running, and "^M" is a carriage return (can be entered with Ctrl-V Ctrl-M).

This in turn can easily be wrapped in a script called "p" which takes "cave" (the screen session) and "4" (the player number) as arguments.
 
Old 10-21-2015, 11:47 AM   #8
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 509

Rep: Reputation: 203Reputation: 203Reputation: 203
Hi again,

Posted my reply before seeing your last reply...

My suggestion obviously doesn't help of you don't know the player number etc, as you can't "see" the detached session :-(

If you still want to consider that approach, though, an external "listplayers" command might be achieved by sending the command, then using the "hardcopy" screen command to capture what is on the screen, and viewing that. For example:

Code:
screen -S cave -p 1 -X stuff "c_listallplayers''^M"
screen -S cave -p 1 harcopy /tmp/cave.out
cat /tmp/cave.out
 
Old 10-21-2015, 11:47 AM   #9
sleftar
Member
 
Registered: Sep 2015
Posts: 51

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by cliffordw View Post
Hi there,

Instead of attaching to the screen session and then typing the command, you might consider sending commands to the screen session remotely from your shell (detached from screen).

The command to do this would look something like this:

Code:
screen -S cave -p 1 -X stuff "c_select(AllPlayers[4])^M"
Where "-p 1" is the screen window number in which your game console is running, and "^M" is a carriage return (can be entered with Ctrl-V Ctrl-M).

This in turn can easily be wrapped in a script called "p" which takes "cave" (the screen session) and "4" (the player number) as arguments.
Actually the thing is, whatever is entered to the console is saved simultaneously to a file called log.txt (all server operations in console (not only commands, player leave, announcements, any operations that is made in server etc) is saved in this file) in server files... So I guess linux can get this console input from log.txt file and then can edit and resent to the game console..

Last edited by sleftar; 10-21-2015 at 11:54 AM.
 
  


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
Sending Keystrokes through Shell Script Deepakp1387 Linux - Newbie 2 01-28-2013 09:16 AM
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
Sending mail from shell script sinoob Linux - Server 3 07-07-2011 07:43 AM
Sending keys from a shell script metalx1000 Programming 1 02-09-2007 02:45 PM
Shell script sending mail mfrick Linux - General 5 09-01-2005 07:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:19 AM.

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