
IlovePERL!
Novice
Dec 6, 2012, 12:57 PM
Post #1 of 4
(492 views)
|
|
Looking for assistance with a simple script
|
Can't Post
|
|
Hello, I'm looking for assistance / help on the following. I have a script reading from a file handler, which outputs logs for a program. It then parses these to get the exact folder location. I then have another file handler opened which stores it's contents into an array. It then greps the folder variable from the first while loop, and compares to the array of items from from the 2nd file handler. This is done so there is no duplicate of the folders. It then has an if / elsif statement that compares this for me, and finally writes to the file handler. I've written a few scripts with this / fifo pipes and worked fine, but never had to do it like this with multiple files. 1. The script works, it will not write the folder if already there, and DOES write it if not found in the array. My problem is that the 2nd bit of code seemingly does not keep running. I'm not sure if this is because it's all one block of code, or you can't have two file handlers being continously read from in the same block of code. I know the first part keeps working, because it writes the complete logs to another file, and that file keeps changing with the uploads. Any guidance would be much appreciated. I know some of the code is choppy, using a a few bash strings "not recommended" but that is fine for now. Code below, thank you!!! #!/usr/bin/perl -w use strict; use File::Basename qw(basename); use Sys::Syslog qw(:DEFAULT setlogsock); $|=1; my $fifo_file = "/var/log/proftpd/xferlog.fifo"; my $program = "xfer_ftp"; my $markerfile = "/oc1/store001/smh/sync/marker.kody.test"; my $fullogs = "/var/log/proftpd/fullxfer.log"; my $fullogs_fh; open($fullogs_fh, ">> $fullogs") or die "The file \"$fullogs\" is not accessible.:$!"; my $marker_fh; open($marker_fh, "+>> $markerfile") or die "The file \"$markerfile\" is not accessible, and this will fail.:$!"; my $fifo_fh; open($fifo_fh, "+< $fifo_file") or die "The FIFO file \"$fifo_file\" is missing, and this program can't run without it.:$!"; setlogsock 'unix'; while (my $lines = <$fifo_fh>) { chomp($lines); print $fullogs_fh "$lines\n"; # prints complete logs to the file my @values = split(/ +/, $lines); # cuts for the folder I want in the logs my $folder = `printf "$values[8]" | cut -d/ -f6 | cut -d - -f1`; # cuts again eliminating unwanted characters chomp($folder); while (my @output = <$marker_fh>) { # stores the current folder names into an array my $element = $folder; if (grep {$_ eq $element} @output) { # compares the folder to the array print "do nothing\n"; } # doesn't matter really, will choose error file later elsif (grep {$_ ne $element} @output) { print $marker_fh "$element\n"; } # this prints the new folder to the file else { print "There is something wrong?\n" } } } close $fullogs_fh; close $fifo_fh; close $marker_fh; exit(0); My goal is for it to run all the time, pretty sure the 2nd loop is causing the error.
|