Perl script to create a separte log file that includes required info. 
September 26th, 2008, 03:03 PM
| | Newbie | | Join Date: Sep 2008
Posts: 5
| | Perl script to create a separte log file that includes required info.
I want to create a separate log that includes an I (logIN) , userid, and date/timestamp from a detailed log. This type of data compresses very well so I can store years of it. I need script to create an separate log files that can saved on each server. Since I dont know much about perl scripting. Your help will be appreciated.
Thanx
Val
| 
September 26th, 2008, 04:00 PM
|  | Site Moderator | | Join Date: May 2007 Location: New Hampshire
Posts: 2,406
| |
And what have you tried to do this? Why not try to do it if you haven't and post your code here if you get stuck.
Regards,
Jeff
| 
October 3rd, 2008, 06:29 PM
| | Newbie | | Join Date: Sep 2008
Posts: 5
| | Quote: |
Originally Posted by numberwhun And what have you tried to do this? Why not try to do it if you haven't and post your code here if you get stuck.
Regards,
Jeff |
I tried by using chomp and split function..but I am not able to do.
following is my code... - #!/usr/bin/perl -w
-
$open_FILE="filename";
-
$output_file="newfile";
-
open (FH, "<$open_FILE");
-
@content=<FH>;
-
close(FH);
-
open(FD, "> $output_file");
-
@params=$_;
-
foreach $line (@content)
-
{
-
chomp ($line);
-
$params = split(/ /, $line);
-
-
}
-
i am totally new to perl script..
I m not getting any output from my code...please do help me ..its urgent.
Last edited by eWish; October 3rd, 2008 at 08:33 PM.
Reason: Please use the [code][/code] tags
| 
October 3rd, 2008, 06:37 PM
|  | Expert | | Join Date: Jan 2007 Location: Southern California USA
Posts: 4,027
| | - foreach $line (@content)
-
{
-
chomp ($line);
-
@params = split(/ /, $line);
-
print FD "@params\n";
-
}
-
See if that helps at least get some data into the file. You can worry about formatting after you get this working.
Use code tags otherwise Jeff is going to give you a well deserved tongue lashing ;)
| 
October 3rd, 2008, 08:35 PM
|  | Moderator | | Join Date: Jul 2007 Location: Arkansas
Posts: 898
| |
@Vallabh, Please do use the tags when posting code samples. Thanks. Quote: |
Originally Posted by KevinADC Use code tags otherwise Jeff is going to give you a well deserved tongue lashing ;) | Jeff must need more fiber in his diet either that or he is trying to get to 2000 posts. :) I better run quick before he sees me here.
--Kevin
| 
October 6th, 2008, 07:07 AM
| | Newbie | | Join Date: Oct 2008 Location: Cochin Age: 29
Posts: 4
| |
Post the sample of logs/data that is there in "filename".
Here you are merely splitting the files on a space.
| 
October 6th, 2008, 06:58 PM
| | Newbie | | Join Date: Sep 2008
Posts: 5
| | Quote: |
Originally Posted by maestria Post the sample of logs/data that is there in "filename".
Here you are merely splitting the files on a space. |
Hello friends,
I first of all i did grep in unix and append the to a new file <newlog.log>. Then in perl i created a code..as follow -
$LOGFILE = "/opt/app/siteminder/log/newlog1.log";
-
open(LOGFILE) or die("Could not open log file.");
-
foreach $line (<LOGFILE>) {
-
$w = "(.+?)";
-
$line =~ m/^$w $w \[$w:$w $w\] " $w"/;
-
-
$Event = $1;
-
$servername = $2;
-
$date = $3;
-
$time = $4;
-
$gmt = $5;
-
$uid = $6;
-
print ("\t","\n","\t", $Event, $date, $time, $uid);
-
-
# do line-by-line processing.
-
}
-
close(LOGFILE);
and also I am getting O/p
but problem is that I did grep and created new file manually... now I want to do through perl....since we have 8 servers and also there many log previously created on each server. so please help me further.......
Last edited by eWish; October 6th, 2008 at 09:02 PM.
Reason: Please use code tags
| 
October 6th, 2008, 08:47 PM
|  | Expert | | Join Date: Jan 2007 Location: Southern California USA
Posts: 4,027
| | Quote: |
Originally Posted by Vallabh Hello friends,
I first of all i did grep in unix and append the to a new file <newlog.log>. Then in perl i created a code..as follow
$LOGFILE = "/opt/app/siteminder/log/newlog1.log";
open(LOGFILE) or die("Could not open log file.");
foreach $line (<LOGFILE>) {
$w = "(.+?)";
$line =~ m/^$w $w \[$w:$w $w\] " $w"/;
$Event = $1;
$servername = $2;
$date = $3;
$time = $4;
$gmt = $5;
$uid = $6;
print ("\t","\n","\t", $Event, $date, $time, $uid);
# do line-by-line processing.
}
close(LOGFILE);
and also I am getting O/p
but problem is that I did grep and created new file manually... now I want to do through perl....since we have 8 servers and also there many log previously created on each server. so please help me further....... | Help you with what? You have not asked a question anyone can help you with. Why didn't you post a sample of the file like you were asked to?
| 
October 7th, 2008, 05:05 PM
| | Newbie | | Join Date: Sep 2008
Posts: 5
| | Quote: |
Originally Posted by KevinADC Help you with what? You have not asked a question anyone can help you with. Why didn't you post a sample of the file like you were asked to? | I want my log file to be look like this.
Event timestamp UserID
I 27/Aug/200823:06:23 uid=PTL1002
I if auth is accepted
Oif rejected.
I m getting the output but I did grep function manually in UNIX. I want to do grep function is perl so that all process can be automatic
| 
October 7th, 2008, 07:16 PM
|  | Site Moderator | | Join Date: May 2007 Location: New Hampshire
Posts: 2,406
| | Quote: |
Originally Posted by Vallabh I want my log file to be look like this.
Event timestamp UserID
I 27/Aug/200823:06:23 uid=PTL1002
I if auth is accepted
Oif rejected.
I m getting the output but I did grep function manually in UNIX. I want to do grep function is perl so that all process can be automatic | Ok, then you can either initiate the same grep function using either backtics or the system() function, or, see if Perl's grep function will work for you.
Regards,
Jeff
| 
October 7th, 2008, 07:29 PM
|  | Expert | | Join Date: Jan 2007 Location: Southern California USA
Posts: 4,027
| | Quote: |
Originally Posted by Vallabh I want my log file to be look like this.
Event timestamp UserID
I 27/Aug/200823:06:23 uid=PTL1002
I if auth is accepted
Oif rejected.
I m getting the output but I did grep function manually in UNIX. I want to do grep function is perl so that all process can be automatic | What does the input file look like?
Maybe English is not your first language, but your English grammar and spellling is not good and is making it difficult to understand you. Try to use good spelling and grammar as much as you can.
| 
October 8th, 2008, 03:52 PM
| | Newbie | | Join Date: Sep 2008
Posts: 5
| | Quote: |
Originally Posted by KevinADC What does the input file look like?
Maybe English is not your first language, but your English grammar and spellling is not good and is making it difficult to understand you. Try to use good spelling and grammar as much as you can. | thanx for help kevin....but I dont know why you are not getting my point.....anyways Input looks like this
AuthAccept bos54637 [01/Oct/2008:22:46:15 -0500] "90.168.25.34 cn=region2,ou=Accounts,o=wireless.com" "leasereplacement GET /XNGALL
" [idletime=3600;maxtime=7200;authlevel=5;] [0] [] []
If you need more tell me...
| 
October 8th, 2008, 06:01 PM
|  | Expert | | Join Date: Jan 2007 Location: Southern California USA
Posts: 4,027
| | Quote: |
Originally Posted by Vallabh thanx for help kevin....but I dont know why you are not getting my point.....anyways Input looks like this
AuthAccept bos54637 [01/Oct/2008:22:46:15 -0500] "90.168.25.34 cn=region2,ou=Accounts,o=wireless.com" "leasereplacement GET /XNGALL
" [idletime=3600;maxtime=7200;authlevel=5;] [0] [] []
If you need more tell me... | OK, now earlier you posted this: -
$Event = $1;
-
$servername = $2;
-
$date = $3;
-
$time = $4;
-
$gmt = $5;
-
$uid = $6;
-
Now show me from the line you posted what each of those should be from the line you posted: -
$Event = AuthAccept
-
$servername = bos54637
-
$date = 01/Oct/2008
-
$time = 22:46:15
-
$gmt = -0500
-
$uid = ????
-
|  | | Thread Tools | Search this Thread | | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,662 network members.
|