LinuxQuestions.org
Review your favorite Linux distribution.
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 09-10-2009, 02:04 AM   #1
sheraz
LQ Newbie
 
Registered: Sep 2007
Posts: 9

Rep: Reputation: 0
Question Want to write a script for calculating usage of software from text file contains log


Hi All,


Actually i m new to scripting in Linux, we have RedHat Server Edition 4 in which different software licences are installed and software itself installed at client side. the usage of the software is recorded daily in a text file which is of format




11:13:06 (FluentLm) OUT: "fluent-par" cfd@headnode2
11:14:19 (FluentLm) OUT: "fluentall" cfd@usr-hpcc-09
11:14:19 (FluentLm) OUT: "gambit" cfd@usr-hpcc-09
11:15:52 (FluentLm) IN: "fluentall" cfd@usr-hpcc-09
11:15:52 (FluentLm) IN: "gambit" cfd@usr-hpcc-09
11:17:05 (FluentLm) IN: "fluent-par" cfd@headnode2
11:17:05 (FluentLm) OUT: "fluent-par" cfd@headnode2
11:21:05 (FluentLm) IN: "fluent-par" cfd@headnode2
11:21:06 (FluentLm) OUT: "fluent-par" cfd@headnode2
11:25:37 (FluentLm) IN: "fluentall" cfd@usr-hpcc-09
11:25:37 (FluentLm) OUT: "fluent" cfd@usr-hpcc-09
11:27:05 (FluentLm) IN: "fluent-par" cfd@headnode2
11:27:05 (FluentLm) OUT: "fluent-par" cfd@headnode2
11:28:05 (FluentLm) IN: "fluent-par" cfd@headnode2


Here

OUT shows the time when users starts using software at client side.
IN shows the time when user stop using the software and close it.
"sometext" in quotes shows the utility of software being used.
text before @ shows user and text after @ shows client PC name.



There are some lines in the text file which shows the license up conditions and errors if any

9:10:48 (FluentLm) FLEXnet Licensing version v10.8.5.0 build 31891 i86_re3
9:10:49 (FluentLm) Server started on headnode2 for: fluentall
9:10:49 (FluentLm) fluent fluent-nox gambit
9:10:49 (FluentLm) geom-trans tgrid flowlab
9:10:49 (FluentLm) flowlab-solv fluent-par fluent-fcell
9:10:49 (FluentLm) EXTERNAL FILTERS are OFF

This is for info only. actual work has to done with above mentioned cutting of file.



I want to write a script that checks that for any OUT & IN, if utility, user and Client PC Name are same then subtract OUT Time from IN Time. This has to be done for each & every user and utility.


I hope, you understand what I want.

Is there any GUI programming possible in Linux.

Kindly, assist me. I will be thankful to all of u.



Regards,

Syed Muhammad Sheraz

Last edited by sheraz; 09-10-2009 at 02:08 AM.
 
Old 09-10-2009, 07:28 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
awk would be a good tool for that. There are plenty of awk tutorials on the web; study them, try some things and post again when you get stuck or have some doubts.

Generally, people on LQ will help you but will not write programs to order. "A helping hand but not a hand out".
 
Old 09-10-2009, 07:41 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
An alternative lang would be Perl; it's very good at text wrangling;
http://perldoc.perl.org/
 
Old 09-11-2009, 11:31 PM   #4
sheraz
LQ Newbie
 
Registered: Sep 2007
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
awk would be a good tool for that.
Thanks for assistance.


I have tried awk . Using awk, grep and sed, i have difficulty in extracting time string. I dont get any idea from internet that how to grep time string from text file.



Regards

Syed Muhammad Sheraz
 
Old 09-12-2009, 01:21 AM   #5
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by sheraz View Post
Thanks for assistance.


I have tried awk . Using awk, grep and sed, i have difficulty in extracting time string. I dont get any idea from internet that how to grep time string from text file.
As others have said, people here will help you write your script, but we want to see you working on it yourself.

Just as a hint, here is a way to separate the time stamp from the other fields:

Code:
while read line
do
   fields=($line)
   echo ${fields[0]}
done
Write a script with the above content and pipe the data to it:

$ script-name.sh < data.file

Here's the result for the data in your original post:

11:13:06
11:14:19
11:14:19
11:15:52
11:15:52
11:17:05
11:17:05
11:21:05
11:21:06
11:25:37
11:25:37
11:27:05
11:27:05
11:28:05

The other fields are available in the same way for each line of your data, because the fields don't have embedded spaces. If they did, it's still soluble, just a bit more difficult.
 
Old 10-06-2009, 03:34 AM   #6
sheraz
LQ Newbie
 
Registered: Sep 2007
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by lutusp View Post
As others have said, people here will help you write your script, but we want to see you working on it yourself.
I was on leave, thanks for your help.
Obviously, i don't want that you people give me a complete solution without my any effort. Basically, i am doing scripting on linux for the first time and the work i am doing is not showing to you b/c it contains many just i have tested not any sequence.
I have written my query in detail so that you people got understand what i need.

Now i am trying to apply if else conditions but it didnt work. I want to obtain lines with IN and OUT of same user and subtract time.

Kindly Assist me.


Thanks for all you people.



Regards,

Syed Muhammad Sheraz
 
Old 10-06-2009, 03:58 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by sheraz View Post
Kindly Assist me.
People here will help you when you post what you have tried and the output from it. It's easier to read if you put it in code tags. You may find LQ's How To Ask a Question helpful.
 
Old 10-06-2009, 04:05 AM   #8
mbostwick
Member
 
Registered: Feb 2009
Location: Where ever life takes me
Distribution: gentoo,opensuse,ubuntu, arch
Posts: 110

Rep: Reputation: 18
It may also be helpful to read the man page on awk.
 
  


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
After log roll, Postfix cannot write to log file, Ubuntu 8.04 mboudro Linux - Server 6 09-17-2010 04:10 AM
need to write a shell script for appending text into each line of a file nandakv4 Programming 9 08-15-2009 04:32 AM
Shell Script or perl help. to write sections of a log to a tmp file for mailing pobman Programming 2 02-02-2009 04:30 PM
Write Error Log to Text File jamez15 Linux - General 3 07-02-2006 08:32 PM
php script can not write text file lemotion Linux - Newbie 5 04-20-2004 11:14 PM


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