Organizing a log


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Organizing a log
# 1  
Old 08-31-2010
Organizing a log

I have a bunch of log files generated from a shell script, its all of my facebook friends and if theyre logged in. Each file is a different person. It runs every 5 minutes. The log file is just the date and time, then 1 if theyre logged in or 0 if theyre not. part of one of the files is:

Code:
Mon Aug 30 17:11:13 EDT 2010 = 0
Mon Aug 30 17:16:13 EDT 2010 = 0
Mon Aug 30 17:21:13 EDT 2010 = 0
Mon Aug 30 17:26:13 EDT 2010 = 0
Mon Aug 30 17:31:13 EDT 2010 = 1
Mon Aug 30 17:36:17 EDT 2010 = 1
Mon Aug 30 17:41:13 EDT 2010 = 0
Mon Aug 30 17:46:14 EDT 2010 = 0
Mon Aug 30 17:51:14 EDT 2010 = 0

so they logged in from around 17:31 to around 17:36.
I am wondering if it would be possible to get just that. Get that information from the log and output it like that, John Smith logged in from 7:30 to 10:00 on Monday, August 30. If you would like to know how i'm logging it i could show that too, in case theres another way i could log it so its like that. also, i'm using bash on OS X.

if theres another post like this, please, direct me to it. I wasn't sure what to search for.
# 2  
Old 08-31-2010
Applied to your sample, this script
Code:
#!/bin/bash
IFS='='
C=0
while read A B
do
	if (($B-$C))
	then	(($B)) && echo -n "logged in from $A" || echo "to $A"
	fi
	C=$B
done <logfile

gives the following result
Code:
logged in from Mon Aug 30 17:31:13 EDT 2010 to Mon Aug 30 17:41:13 EDT 2010

Maybe it would be better to modify the generating script to provide somethging similar.
# 3  
Old 09-01-2010
thanks, frans, thats exactly what I wanted. I'll just change the date format. thanks for the help.

---------- Post updated at 11:42 PM ---------- Previous update was at 05:34 PM ----------

well, sadly, the first few times it worked like a charm! and, i got it going with awk to show how many minutes they were logged in, too! but, for some odd reason, it still works and prints the results, but i get an error.

Code:
organize.sh: line 6: ((: -: syntax error: operand expected (error token is "-")
organize.sh: line 6: ((: 0-: syntax error: operand expected (error token is "-")

obviously, i named it organize.sh.
# 4  
Old 09-01-2010
That's certainly due to a line (the last one?) in your log file that doesn't contain the '=' sign. So it reads A and B but B is empty. A turnaround : insert the bold command
Code:
while read A B
do
        B=${B:-0} # if B is empty, then set it to 0
	if (($B-$C))
	then (($B)) && echo -n "logged in from $A" || echo "to $A"
	fi
	C=$B
done <logfile

# 5  
Old 09-01-2010
ah thank you. now there is no error and it also removes duplicates. I was changing things yesterday and some of the lines are messed up, and the date didnt change for 5 entries, and before it showed all 5, but now it only shows 1. also, I did stop it from saying the error myself, by changing
Code:
if (($B-$C))

to
Code:
if [ $B-$C ]

# 6  
Old 09-01-2010
As you can see the result with this little script, the result of [ $B-$C ] is always true.
Code:
#!/bin/bash
for B in 0 1
do
	for C in 0 1
	do
		echo -n "B=$B C=$C ((\$B-\$C)) --> "
		if (($B-$C))
		then echo -n "TRUE "
		else echo -n "FALSE"
		fi
		echo -n "    [ \$B-\$C ] --> "
		if [ $B-$C ]
		then echo "TRUE"
		else echo "FALSE"
		fi
	done
done

The logic i involved ist that it should do something if second field is different from previous line and the result of previous script is
Code:
B=0 C=0 (($B-$C)) --> FALSE    [ $B-$C ] --> TRUE
B=0 C=1 (($B-$C)) --> TRUE     [ $B-$C ] --> TRUE
B=1 C=0 (($B-$C)) --> TRUE     [ $B-$C ] --> TRUE
B=1 C=1 (($B-$C)) --> FALSE    [ $B-$C ] --> TRUE

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please help me in organizing the data in UNIX

I have an output file in the form Hostname Value1=abc Value2=def Value3=xyz Hostname1 Value1=abc1 Value2=def1 Value3=xyz1 Hostname2 Value1=abc2 Value2=def2 Value3=xyz2 | | | And so on….. I need to export this output into csv so then it should be in format (8 Replies)
Discussion started by: rahul2662
8 Replies

2. Shell Programming and Scripting

Organizing text file by Capital Names (capital word ' ' capital word)

Hi I have a file passwd_exmpl that contains: root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync... (5 Replies)
Discussion started by: eladage
5 Replies

3. HP-UX

Script to monitor /var/opt/resmon/log/event.log file

AM in need of some plugin/script that can monitor HP-UX file "/var/opt/resmon/log/event.log" . Have written a scrip in sh shell that is working fine for syslog.log and mail.log as having standard format, have interrogated that to Nagios and is working as I required . But same script failed to... (3 Replies)
Discussion started by: Shirishlnx
3 Replies

4. Shell Programming and Scripting

help with organizing some non regular text

hey im trying to get the hex diffrences in two files ones called new and the other is named old i want it to phrase into my script, heres how i need the info: input='\x'94 #the new 1 byte hex change offset=00000000 #the 1st offset of the difference patch unset input offset input='\x'34... (5 Replies)
Discussion started by: lewisdenny
5 Replies

5. Programming

Organizing C++ Code

I have three directories CspInterp, FpnInterp and LinInterp. Each directory contains 4 .h and .ccp files describing 4 classes each CspInterp class CspFsInterp1d : public FsInterp1d class CspVsInterp1d : public VsInterp1d class CspFsInterp2d : public FsInterp2d class CspVsInterp2d : public... (10 Replies)
Discussion started by: kristinu
10 Replies

6. Shell Programming and Scripting

How can view log messages between two time frame from /var/log/message or any type of log files

How can view log messages between two time frame from /var/log/message or any type of log files. when logfiles are very big and especially many messages with in few minutes, I would like to display log messages between 5 minute interval. Could you pls give me the command? (1 Reply)
Discussion started by: johnveslin
1 Replies

7. Shell Programming and Scripting

Organizing log

Hello, Following are the log of my sms application COMMAND: #tail -30 /var/log/smsd.log | grep Message_id | awk '{print $1,$2,$9}' OUTPUT: 2011-02-21 12:16:20,5, 03218975857, 2011-02-21 12:16:26,5, 03323048252, 2011-02-21 12:16:53,5, 03323048252, 2011-02-21 12:16:59,5,... (1 Reply)
Discussion started by: telnor
1 Replies

8. Shell Programming and Scripting

Organizing Files

Hi, I'm fairly new at scripting. I need to write a script that takes files from a source directory puts them in a target directory and sorts them by artist name. This is what I have so far #!/bin/bash source_dir='/home/tcindy/songs' target_dir='/home/tcindy/music' for path in... (2 Replies)
Discussion started by: tcindy
2 Replies

9. Shell Programming and Scripting

Help organizing a music directory with sub directories.

Hello all, I used to have a great script and I lost it :( What the script did was searched a directory named say "music" It searched all sub directories for .mp3 files Then placeed all the .mp3's into a directory of the band name It also renamed the .mps "track#, band name, album name" (I... (9 Replies)
Discussion started by: komputersman
9 Replies
Login or Register to Ask a Question