[Melbourne-pm] Writing array data to file with appended information

Camillo Pereira camillo.pereira at gmail.com
Thu Mar 26 22:44:35 PDT 2009


I have the following scenario where I need to extract node name information
based on certain conditions from an application, and write the data out to a
file and HUP the process concerned.  I have managed to get to a certain
point however need some advise.

Script output:

use strict;
use warnings;

## Cut down version of regex list

my @critical_device_def = (
    [AAA    => qr{...apb09}    ],
    [BBB    => qr{...avggd09}    ],
    [CCC => qr{...uytwop09}    ],
    [DDD => qr{...loupoi09}   ]


my $file = "rules.txt";
my @tokens;

open(UPDATE, ">$file") || die "Can't open new file: $!\n";

@DEVICE_LIST=`/opt/OV/bin/ovtopodump | awk '\$3 ~
/^[a-z]+.*\.my\.domain\.com\.au/{print \$3}'| uniq`;

foreach (@DEVICE_LIST)
    for my $t (@critical_device_def)
      my ($site, $device, $flag) = @$t;
      if ($_ =~ m/\G($device)/gc)

        print UPDATE "$_" ;




The problem I am having is that at the print UPDATE line, I need to append
to the data a tab and the number 1.  With the current code, the file output
looks like this:


however, I need the contents to be printed to the file in the format below
where the hostname then a tab and the number one is printed:

cpploupoi09.my.domain.com.au <tab_space> 1
cpqavggd09.my.domain.com.au <tab_space> 1

What is the best way to do this?

Also what is the best way to send a HUP signal to a running Unix process?

Appreciate your help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/melbourne-pm/attachments/20090327/cbab869f/attachment.html>

More information about the Melbourne-pm mailing list