[Melbourne-pm] Writing array data to file with appended information
Hamish Carpenter
hamish at hamishcarpenter.com
Fri Mar 27 03:07:21 PDT 2009
Camillo,
I believe the output you are getting has a newline at the end of
each domain. You will need to chomp() each line of output to remove
the newline and then manually append a new line.
chomp;
print UPDATE "$_\t1\n";
See `perldoc -f chomp` for more info on chomp.
Hamish
Camillo Pereira wrote:
> Thanks for the reply.
>
> This is something that I had tried as well, however, the format of the
> file ends up looking like the following:
>
> cpploupoi09.my.domain.com.au <http://cpploupoi09.my.domain.com.au>
> cpqavggd09.my.domain.com.au
> 1cabloupoi08.my.domain.com.au
> 1cacloupoi07.my.domain.com.au
> 1cadloupoi06.my.domain.com.au
> 1caeloupoi05.my.domain.com.au
> 1cafloupoi06.my.domain.com.au
> 1
>
> Thanks for HUP signal part. I will use the system() function to send
> the command.
>
> Any other hints in relation to the previous item?
>
>
> 2009/3/27 Mathew Robertson <mathew.robertson at netratings.com.au
> <mailto:mathew.robertson at netratings.com.au>>
>
> print UPDATE "$_\t1"
>
>
> "ps auxww" will give you a process list, from which you can get the
> PID, so that you can call "kill -HUP <PID>"
>
> Hope this helps,
> Mathew Robertson
>
> Camillo Pereira wrote:
>> Hi,
>>
>> 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:
>>
>> #!/usr/bin/perl
>> 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 @DEVICE_LIST;
>> 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 "$_" ;
>> next;
>> }
>>
>> }
>>
>> }
>>
>> =====
>>
>> 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:
>>
>> cpploupoi09.my.domain.com.au <http://cpploupoi09.my.domain.com.au>
>> cpqavggd09.my.domain.com.au <http://cpqavggd09.my.domain.com.au>
>>
>> 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 <http://cpploupoi09.my.domain.com.au>
>> <tab_space> 1
>> cpqavggd09.my.domain.com.au <http://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.
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Melbourne-pm mailing list
>> Melbourne-pm at pm.org <mailto:Melbourne-pm at pm.org>
>> http://mail.pm.org/mailman/listinfo/melbourne-pm
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Melbourne-pm mailing list
> Melbourne-pm at pm.org
> http://mail.pm.org/mailman/listinfo/melbourne-pm
More information about the Melbourne-pm
mailing list