LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 02:36 AM   #1
sleftar
Member
 
Registered: Sep 2015
Posts: 50

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, 08:35 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,087
Blog Entries: 10

Rep: Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521
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, 08:42 AM   #3
slacksam
Member
 
Registered: Oct 2012
Location: Germany
Distribution: Slackware, Salix, Manjaro, Arch
Posts: 133

Rep: Reputation: 14
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, 11:21 AM   #4
sleftar
Member
 
Registered: Sep 2015
Posts: 50

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 11:44 AM.
 
Old 10-21-2015, 12:03 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,931

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
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, 12:27 PM   #6
sleftar
Member
 
Registered: Sep 2015
Posts: 50

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 12:37 PM.
 
Old 10-21-2015, 12:37 PM   #7
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 481

Rep: Reputation: 179Reputation: 179
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, 12:47 PM   #8
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 481

Rep: Reputation: 179Reputation: 179
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, 12:47 PM   #9
sleftar
Member
 
Registered: Sep 2015
Posts: 50

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 12:54 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


All times are GMT -5. The time now is 10:26 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration