ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello everyone. I need some help writing a perl script. I have been going crazy trying to write this script. I should mentiont that I am new to Perl, so I am learning as much as I can.
Here is what I want to do:I am trying to extract information from a firewall log and put it into a new file. I only want to extract certain pieces of information. Here are a few examples:
Let me show what I am trying to pull out of the file:
(This is where the inital block occurs, the firewall will then continue to block all attempts from this IP address.I would like to extract all entries in the firewall like this one.)
03/13/03 16:44:57 firewalld103 deny in eth0 48 tcp 20 117 212.241.11.21 209.126.xxx.xxx 4449 80 syn (LO-Proxied-HTTP)
(At this point, the firewall continues to block the attempt. I would like to extract all lines in the firewall that contain this as well...contains very useful information such as ports and packet sizes.)
With that in mind, can I ask for someone to help me build my script? I feel like I am butting my head against a wall. I know I have much to learn, but can learn a lot from seeing the script and breaking it down to see how it functions.
I really need help. If someone can help me write this script, I would be extremely grateful.
Oh, my mistake. Sorry about that. I was trying to get some additional information that may be helpful. I showed two different instances of blocking going on against different IP addresses. Both have the same results, just different IP addresses.
The differences were actually the :s
03/13/03 16:44:56 kernel Temporarily blocking host 212.241.116.21
04/09/03 15:34 kernel: Temporarily blocking host 172.174.112.156
You can set the script to pick up whatever you want - just modify the if statement.
In this case the lines containing "foo", "bar" and "chocolate bar" will be put in the new file.
if($line =~ /foo/ || $line =~ /bar/ || $line =~ /chocolate bar/){
The expression "$line =~ /foo/" says - look for "foo" in variable "$line". As $line is not modified we can just append $line to the file and we get the whole line.
Very interesting.
Now that I understand how to pick out a certain line of text,
can I setup another string to pick out additional text? For instance, if the word blocked appears anywhere in the file, can I add that to this script as well and output it to the same file?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.