Visit Our UNIX and Linux User Community

Script to match lines in screen

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to match lines in screen
# 1  
Old 03-06-2015
Script to match lines in screen

I'd like to ask people who knows bash scripting to write me a script which would open a specific screen and match lines.

Here is algorithm I'm thinking about.
  1. Find SCREENS named name1, name2.... and nameX.
  2. Open them one by one and type 'STATS'
  3. Match last lines of the screen before command type and after.
  4. If lines don't match - move on to the next screen, if they do close current screen and run gaming server start line (I'll write this myself).

Note: Lines matching should be performed few times with few mins delays.

So the context of my problem is that I have few Counter-Strike gaming servers. Sometimes they crash and I have manually restart them. I'd like this to change.

I'm using Debian 6.0 32bit.

Last edited by rbatte1; 03-06-2015 at 02:43 PM.. Reason: Added LIST=1 tags
# 2  
Old 03-06-2015
I'm not sure by what you mean for 'open the screens'. Is this firing up an application or something?

Finding the files should be easy with the find command, but pushing in the word STATS may defen on what you are actually doing to how you push it in.

Can you show us the content of these files and the code you are running to 'open' them?

Please wrap code and data input/output in CODE tags, like this:-
[CODE]This is my code[/CODE]
to produce the following (fixed character width, space respected):-
This is my code

Not only does it make posts far easier to read, but CODE and ICODE sections respect multiple space and have fixed width characters, which is important for easily seeing input/output requirements.

# 3  
Old 03-06-2015
When I type
screen -r

I get list of screens
In each of them I run my gaming server. So screen works like a console. When I open some screen
screen -r pb

I see the following

If I type "STATS" when server is online last line always changes.
If server would be offline last line would remain the same before and after typing "STATS".

Each screen I create with similar line
screen -A -m -d -S pb linux32 ./hlds_run -game cstrike +map de_dust2_2x2 +maxplayers 21 +port 27017 +ip

# 4  
Old 03-08-2015
So, this is screen as in vt100 sessions using a GUI or the like then I think.

I regret that I do not have that software installed and have never explored it. perhaps another can offer you some assistance.

Sorry about that, Smilie

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to combine lines if fields match in lines

In the awk below, what I am attempting to do is check each line in the tab-delimeted input, which has ~20 lines in it, for a keyword SVTYPE=Fusion. If the keyword is found I am splitting $3 using the . (dot) and reading the portion before and after the dot in an array a. If it does have that... (12 Replies)
Discussion started by: cmccabe
12 Replies

2. Shell Programming and Scripting

Match the value & print lines from the match

Hello, I have a file contains two columns. I need to print the lines after “xxx” so i'm trying to match "xxx" & cut the lines after that. I'm trying with the grep & cut command, if there any simple way to extract this please help me. Sample file : name id AAA 123 AAB 124 AAC 125... (4 Replies)
Discussion started by: Shenbaga.d
4 Replies

3. UNIX for Dummies Questions & Answers

awk - (URGENT!) Print lines sort and move lines if match found

URGENT HELP IS NEEDED!! I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but - Currently, script is not printing lines to File3.txt in order. - Also the matching lines are not moving out of File1.txt ... (1 Reply)
Discussion started by: High-T
1 Replies

4. Shell Programming and Scripting

Script to match strings that sometimes are splitted in 2 lines

Hello to all, I have an hexdump -C format as below: 31 54 47 55 48 4c 52 31 5f 52 31 32 31 31 32 ff 44 00 00 0E 01 32 14 56 42 17 47 48 0f ff ff ff 44 00 00 01 32 14 56 00 23 83 95 2f 42 17 47 48 00 0f ff ff 00 15 00 0a 48 00 01 5a 00 02 17 00 00 2f 00 00 30 00 00 31 00 00 ff 34 ff 44 00... (23 Replies)
Discussion started by: Ophiuchus
23 Replies

5. UNIX for Dummies Questions & Answers

awk display the match and 2 lines after the match is found.

Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file. For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt I tried with grep -A but it's not supported on my system. I tried with awk,... (4 Replies)
Discussion started by: eurouno
4 Replies

6. Shell Programming and Scripting

shell script: grep multiple lines after pattern match

I have sql file containing lot of queries on different database table. I have to filter specific table queries. Let say i need all queries of test1,test2,test3 along with four lines above it and sql queries can be multi lines or in single line. Input file contains. set INSERT_ID=1; set... (1 Reply)
Discussion started by: mirfan
1 Replies

7. UNIX for Dummies Questions & Answers

Extracting m lines after n lines after match

Hi All, I would like to extract from a text file m lines skipping n lines after a string occurrency. Is it possible with grep? e.g. qqq ww eee rrr ttt yyy uuu I want to print 2 lines skipping 1 line after the string 'ww' result would be rrr ttt (2 Replies)
Discussion started by: f_o_555
2 Replies

8. Shell Programming and Scripting

sed problem - delete all lines until a match on 2 lines

First of all, I know this can be more eassily done with perl or other scripting languages but, that's not the issue. I need this in sed. (or wander if it's possible ) I got a file (trace file to recreate the control file from oracle for the dba boys) which contains some lines another line... (11 Replies)
Discussion started by: plelie2
11 Replies

9. Shell Programming and Scripting

Perl script to match a pattern and print lines

Hi I have a file (say 'file1')and I want to search for a first occurence of pattern (say 'ERROR') and print ten lines in the file below pattern. I have to code it in PERL and I am using Solaris 5.9. I appreciate any help with code Thanks Ammu (6 Replies)
Discussion started by: ammu
6 Replies

10. Shell Programming and Scripting

awk to compare lines of two files and print output on screen

hey guys, I have two files both with two columns, I have already created an awk code to ignore certain lines (e.g lines that start with 963) as they wou ld begin with a certain string, however, the rest I have added together and calculated the average. At the moment the code also displays... (3 Replies)
Discussion started by: chlfc
3 Replies

Featured Tech Videos