473,241 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

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
Sep 26 '08 #1
12 9465
numberwhun
3,509 Expert Mod 2GB
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
Sep 26 '08 #2
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...
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. $open_FILE="filename";
  3. $output_file="newfile";
  4. open (FH, "<$open_FILE");
  5. @content=<FH>;
  6. close(FH);
  7. open(FD, "> $output_file");
  8. @params=$_;
  9. foreach $line (@content)
  10. {
  11. chomp ($line);
  12. $params = split(/ /, $line); 
  13.  
  14. }
  15.  
i am totally new to perl script..

I m not getting any output from my code...please do help me ..its urgent.
Oct 3 '08 #3
KevinADC
4,059 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. foreach $line (@content)
  2. {
  3. chomp ($line);
  4. @params = split(/ /, $line);
  5. print FD "@params\n";
  6. }
  7.  
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 ;)
Oct 3 '08 #4
eWish
971 Expert 512MB
@Vallabh, Please do use the tags when posting code samples. Thanks.

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
Oct 3 '08 #5
Post the sample of logs/data that is there in "filename".
Here you are merely splitting the files on a space.
Oct 6 '08 #6
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

Expand|Select|Wrap|Line Numbers
  1. $LOGFILE = "/opt/app/siteminder/log/newlog1.log";
  2. open(LOGFILE) or die("Could not open log file.");
  3. foreach $line (<LOGFILE>) {
  4.     $w = "(.+?)";
  5.     $line =~ m/^$w $w \[$w:$w $w\] " $w"/;
  6.  
  7.     $Event     = $1;
  8.     $servername  = $2;
  9.     $date = $3;
  10.     $time     = $4;
  11.     $gmt     = $5;
  12.     $uid      = $6;
  13. print ("\t","\n","\t", $Event, $date, $time, $uid);
  14.  
  15.     # do line-by-line processing.
  16. }
  17. 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.......
Oct 6 '08 #7
KevinADC
4,059 Expert 2GB
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?
Oct 6 '08 #8
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
Oct 7 '08 #9
numberwhun
3,509 Expert Mod 2GB
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
Oct 7 '08 #10
KevinADC
4,059 Expert 2GB
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.
Oct 7 '08 #11
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...
Oct 8 '08 #12
KevinADC
4,059 Expert 2GB
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:

Expand|Select|Wrap|Line Numbers
  1. $Event = $1;
  2. $servername = $2;
  3. $date = $3;
  4. $time = $4;
  5. $gmt = $5;
  6. $uid = $6;
  7.  
Now show me from the line you posted what each of those should be from the line you posted:

Expand|Select|Wrap|Line Numbers
  1. $Event = AuthAccept
  2. $servername = bos54637
  3. $date = 01/Oct/2008
  4. $time = 22:46:15
  5. $gmt = -0500
  6. $uid = ????
  7.  
Oct 8 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: donalmurtagh | last post by:
Hi, I'm looking for a command-like utility which can read a .class file and tell you whether it includes debug information, i.e. whether it was built with the -g option of javac. Thanks in...
1
by: Christian Eriksson | last post by:
Hi! I have a problem using the environment variable LD_LIBRARY_PATH in my perl script. Everything works fine when I set it at the command prompt and then runs my perl script like this: ...
1
by: nsvmani1 | last post by:
Hi there! Does anybody know how to convert the Perl script files into a single exe file non-readable format?? regards venki
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
0
by: susinthaa | last post by:
Hi, Is there any command in perl to create a file in windows for a specified size?
1
by: raghav82 | last post by:
New to perl. c++ file which needs to invoke perl file and provide input for it.how to invoke it.i also want to know setting of environment variable in windows environment using the perl script. i set...
4
by: jonathan184 | last post by:
Hi I have a perl script, basically what it is suppose to do is check a folder with files. Now the files are checked using a timestamp with the command ls -l so the timestamp in this format is...
1
by: jawas | last post by:
Can any body help to write the general Perl script to transfer file from one window XP machine to another window XP machine and then change the file name and send some command for e.g config, 9,9 to...
0
by: somsub | last post by:
Hi All, I am facing a problem while running a perl script through selenium RC server . I recorded oone log in test case with slenium IDE and run it after that with the ide only and it worked...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.