LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 09-21-2003, 07:52 PM   #16
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58

Thanks, druuna, my script really needs the corrections you made to process the long list without errors.

My script only gives 13 hits. (Note that it needs the original logfile, where the records are in natural order (i.e. sorted by time). So I sorted the records posted here by time before feeding it to the script)

As for the difference between the two counts, there are some users like this:

[ Sep 17 19:04:50]~Phanser Adoze~ON
[ Sep 17 19:48:03]~Phanser Adoze~OFF
[ Sep 17 19:54:36]~Phanser Adoze~ON
[ Sep 17 20:35:02]~Phanser Adoze~OFF
[ Sep 17 20:36:55]~Phanser Adoze~ON
[ Sep 18 20:54:39]~Phanser Adoze~ON
[ Sep 18 20:56:11]~Phanser Adoze~OFF
[ Sep 18 21:23:25]~Phanser Adoze~ON
[ Sep 18 22:18:26]~Phanser Adoze~OFF

Is he online?
My script says: not, since he went offline the last time.
Yours may say: yes, since the count of his logins exceeds the count of his logouts.

Who is right?

Last edited by J_Szucs; 09-21-2003 at 08:31 PM.
 
Old 09-21-2003, 08:13 PM   #17
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Original Poster
Rep: Reputation: 30
THIS SCRIPT:

#! /bin/bash

# Location of the file shown in your first post
ALLONOFF="/PATH/TO/ON-OFF-ENTRIES"

# Need sed to strip (multiple) spaces in username
for THIS_USER in `cat ${ALLONOFF} | sed 's/ [ ]*//g' | awk -F~ '{ print $2 }' | sort | uniq`
do

NO_ONLINE="`cat ${ALLONOFF} | sed 's/ [ ]*//g' | grep ${THIS_USER} | grep -c '~ON'`"
NO_OFFLINE="`cat ${ALLONOFF} | sed 's/ [ ]*//g' | grep ${THIS_USER} | grep -c '~OFF'`"

if (( ${NO_ONLINE} != ${NO_OFFLINE} && ${NO_ONLINE} > ${NO_OFFLINE} ))
then
echo "${THIS_USER} : Still on-line."
fi

done
#EOF

Apears to be working. I am getting more players on line then I should though. I think that is because the nwserver (not designed by me) is very TCP/IP senstive and floods it's self to a hang quite often. I'm going to clear the logs and evaluate the info I get. Again, I'll feed back any to all information I get.

BTW, regardless fo who's script I use, I would like to say thank you to everyone who helped. It takes 1 to make 2. <smiles>
 
Old 09-21-2003, 08:29 PM   #18
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58
I think, if you count and compare NO_ONLINE and NO_OFFLINE, user Phanser Adoze mentioned in my previous post will ever seem to be online, though he just simply failed normal logout.
That is why you get more users online than there are actually.

I already cleared your logs and saw many users like that, so I think that only one approach can be applied in this case: the one that only considers the last action of each user.

Last edited by J_Szucs; 09-21-2003 at 08:40 PM.
 
Old 09-21-2003, 08:46 PM   #19
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Original Poster
Rep: Reputation: 30
Okay... So far, it inputs new users who log in correctly... I got my first 3, checked the logs. Check internally in the game, same output. Waiting for one of them to leave.
 
Old 09-21-2003, 11:05 PM   #20
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Original Poster
Rep: Reputation: 30
Okay, technically speaking, everything is running fine. There apears to be no bugs.

Now, realistically speaking, I see 1 thing this script needs, BAD:

Is there any way the script can be setup to "refresh" the screen instead of clearing it? Using "sleep #" + "clear" causes huge cpu spikes. In fact reducing it from it's current setting can spike the cpu from 20% to 100% for 1/2 a second.

Here's my script:

#! /bin/bash
# Chris Jepson(Dolvmin), Unknown(druuna)
# 09-21-03 [6:20AM EST]
# This is a test script to display players currently on line.
# |--------------------------------------------------------------------------------|
# | I dedicate this line as a thank you to all the script writers. |
# | If it was not for them, I may not not been able to finish this. -Chris Jepson |
# |--------------------------------------------------------------------------------|

LOGDIR=/home/nwserver/logs.0
LOGFILE=/home/nwserver/logs.0/nwserverLog1.txt
BUFFER=/home/nwserver/logs.0/buffer.mem
BUFFER2=/home/nwserver/logs.0/buffer2.mem
LOG=/home/nwserver/logs.0/PLAYER.LOG
LOOP=1

clear

while [ "$LOOP"!=0 ]
do

tput cup 0 0; echo "| *PLAYERS ONLINE* |" # GUI START
tput cup 1 0; echo "|-------------------------------|"
tput cup 2 0; echo " "
tput cup 3 0; echo " "
tput cup 4 0; echo " "
tput cup 5 0; echo " " # GUI END
tput cup 2 0
grep Joined $LOGFILE > $BUFFER # Generating Player Log
grep Left $LOGFILE >> $BUFFER
sed 's/] /]~/g' $BUFFER > $BUFFER2
sed 's/ (........) Joined as Player [0-9]/~ON~/g' $BUFFER2 > $BUFFER
sed 's/ (........) Joined as Player [0-9][0-9]/~ON~/g' $BUFFER > $BUFFER2
sed 's/ Left as a Player (..............)/~OFF~/g' $BUFFER2 > $BUFFER
sed 's/ Left as a Player (...............)/~OFF~/g' $BUFFER > $BUFFER2
sed 's/[.]//g' $BUFFER2 > $BUFFER
# Proc. Player Log End

# Beging to proc. who is on from Player Log

# Location of the file shown in your first post
ALLONOFF="$BUFFER"

# Need sed to strip (multiple) spaces in username
for THIS_USER in `cat ${ALLONOFF} | sed 's/ [ ]*//g' | awk -F~ '{ print $2 }' | sort | uniq`

do

NO_ONLINE="`cat ${ALLONOFF} | sed 's/ [ ]*//g' | grep ${THIS_USER} | grep -c '~ON'`"
NO_OFFLINE="`cat ${ALLONOFF} | sed 's/ [ ]*//g' | grep ${THIS_USER} | grep -c '~OFF'`"

if (( ${NO_ONLINE} != ${NO_OFFLINE} && ${NO_ONLINE} > ${NO_OFFLINE} ))
then
echo " *PLAYER* - ${THIS_USER}" > $LOG # Player Log ready.
awk -F: '{ printf "%-30s\n", $1}' $LOG # Display the Log.
fi

done # "for" loop

sleep 10
clear

done # "while" loop


# [EOF]

Last edited by dolvmin; 09-21-2003 at 11:07 PM.
 
Old 09-22-2003, 06:30 AM   #21
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
As stated by J_Szucs some users are still on-line if my script is used, although he/she might be off-line (last action in date sorted log is an OFF).

Question is: After the failed log-on (or a 'dirty' log-off) are there still resources being used by the server for this 'logged-off' player.

I think there are. But if that is not the case: My script does not show the correct amount of active on-line players.

@dolvmin

A cpu spike to 100% isn't a bad thing per se. If allowed, a program will consume as much cpu as it needs/is possible. It becomes a problem if multiple programs want/need cpu time and your machine is struggling to keep up. But in that case you will see a 100% count for longer then 0.5 seconds.

Speeding up the script:

Sorry, don't have a solution for the sleep/clear thingie (although I doubt that those are the main problem). There are a few other things I noticed that migth speed up things a bit:

- Script uses a lot of I/O, I'm going to take a look if that can be changed.
- The following isn't needed or can be done better/faster:

line 11 : LOGDIR=/home/nwserver/logs.0 - but LOGDIR isn't used anywhere else. Can be removed.

line 15 & 19 : variable declaration/use (LOOP) not necessary. Remove both lines and replace line 19 with - while true

line 30/31 : why 2 greps?? Can't you use egrep??

egrep "Joined|Left" $LOGFILE > $BUFFER

instead of:

grep Joined $LOGFILE > $BUFFER # Generating Player Log
grep Left $LOGFILE >> $BUFFER

line 56/57 : don't write to file if not absolutely necessary.

echo " *PLAYER* - ${THIS_USER}" > $LOG # Player Log ready.
awk -F: '{ printf "%-30s\n", $1}' $LOG # Display the Log.

This will fill a file with a string and use that file to read/print the string. Very I/O intensive.

replace with:

echo " *PLAYER* - ${THIS_USER}"

or, if you need to justify your output with printf using awk:

echo ${THIS_USER} | awk -v thisuser="${THIS_USER}" '{ printf "%-12s%-18s\n", " *PLAYER* - ", thisuser }'

and line 14 (LOG=/home/nwserver/logs.0/PLAYER.LOG) is now obsoleet, delete it.

Will take a longer/harder look if I have the time. For now: Hope this helps.

I do have a request: Can you post a relevant part of the raw input file (nwserverLog1.txt). I do believe the sed statements can be done better/faster, but I need to see the raw lines for that.

Last edited by druuna; 09-22-2003 at 06:48 AM.
 
  


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
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
bash script and grep syros Programming 4 01-13-2005 03:04 PM
Simple Text Reformat (sed and grep) mikefazz Programming 2 08-31-2004 07:38 PM
sed script glam1 Programming 2 08-31-2004 11:28 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM


All times are GMT -5. The time now is 09:41 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration