in reply to creating a perl script

I don't fully understand your question, but I first notice that your program as it is written, should not find any matching line in your log. The reason is that you are using

if($_ == "has gone down" ) { ... }
to check for the interesting lines. $_ certainly will never be exactly the string has gone down, because at least it will have a \n at the end, plus, according your description, it has some more information in this line (such as the timestamp).

If you are only interested in lines containing that magin string, the easiest way would be to use index. Note that index returns -1 on failure.

If you need, however, some of the other fields in the logline as well, in order to run your start server command, you are better of using regular expressions. For example if you need the server name and port, you could write something like

if(/Server\s(.+):(\d+) has gone down/) { my $server=$1; my $port=$2; ... }

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^2: creating a perl script
by swampyankee (Parson) on Feb 12, 2009 at 14:14 UTC

    ...and, of course, one should use eq vs == for a string comparison. The string on the right side of the test ("has gone down") will numify as 0, which will match any string that numifies as 0, which is probably most of them.


    Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

Re^2: creating a perl script
by tweetiepooh (Hermit) on Feb 12, 2009 at 17:13 UTC
    Adding to the code above
    my %downserver = (); if (...) { my $server = $1; if (!exists $downserver{$server}) { $downserver{$server} = "Restarting $server"; run start server command } }
    or you could maintain the list and process at the end.
    my %downserver = (); if (...) { my $server = $1; my $downtime = $n; # some other extracted bit from regex $downserver{$server} = $downtime; } foreach my $server (keys %downserver) { if ($downserver{$server) down after last run) { run start server write to log server upped } }