safiyet_80777
Aug 09, 2011Nimbostratus
add a member to a external data group with a perl script.
Hi,
I want to write a perl script which adds a member to a external data group. New members are included in a text file that:
x.txt
AAAA;external_data
AAAA is a new member. but I do not want to lose old members also. so I wrote a perl script that is in below.
after running perl script, external_data group file would be :
"AAAA",
IlZWVlYiLA==
As a result, the txt data is written normally but old data is written by a different format.
I want to run script in f5, so I must use perl script.
Please help me.
Thanks.
!/usr/bin/perl
use SOAP::Lite;
use integer;
----------------------------------------------------------------------------
sub listStrings
----------------------------------------------------------------------------
sub listStrings()
{
open(FILE, 'x.txt') or die "Can not read file!"; datagroup okundu
my $data_file = '/etc/hys/temp.txt';
open TEMPFILE, ">$data_file" or die "can't open $data_file $!";
binmode(TEMPFILE);
while () {
chomp; no newline
s/.*//; no comments
s/^\s+//; no leading white
s/\s+$//; no trailing white
next unless length; anything left?
my ($var, $value) = split(/\s*;\s*/, $_, 2);
$sclass_members = $var;
$sdata_group = $value;
$sclass_members = "\"" . "$sclass_members" . "\",";
$soapResponse = $Class->get_external_class_file_name
(
SOAP::Data->name(class_names => [$sdata_group])
);
@file_names = @{$soapResponse->result};
$fileName = @file_names[0];
$chain_type = $FILE_FIRST;
$chunk_size = 65536;
$file_offset = 0;
print TEMPFILE "$sclass_members\n";
$StringClass =
{
name => $sdata_group,
members => [$sclass_members]
};
my ($class, $string) = (@_);
$StringClass =
{
name => $sdata_group,
members => [$sclass_members]
};
$soap_response = $ConfigSync->download_file
(
SOAP::Data->name(file_name => $fileName),
SOAP::Data->name(chunk_size => $chunk_size),
SOAP::Data->name(file_offset => $file_offset)
);
$FileTransferContext = $soap_response->result;
$file_data = $FileTransferContext->{"file_data"};
$chain_type = $FileTransferContext->{"chain_type"};
@params = $soap_response->paramsout;
$file_offset = @params[0];
Append Data to File
print TEMPFILE $file_data;
close (TEMPFILE);
open(TEMPFILE, "<$data_file") or die("Can't open $localFile for input: $!");
binmode(TEMPFILE);
$file_data = "";
$bytes_read = read(TEMPFILE, $file_data, $chunk_size);
$FileTransferContext =
{
file_data => SOAP::Data->type(base64 => $file_data),
chain_type => $chain_type
};
$soap_response = $ConfigSync->upload_file
(
SOAP::Data->name(file_name => $fileName),
SOAP::Data->name(file_context => $FileTransferContext)
);
if ( $soap_response->fault )
{
print $soap_response->faultcode, " ", $soap_response->faultstring, "$file_data $chain_type\n";
}
close (TEMPFILE);
}
close(FILE);
$ConfigSync->load_configuration("/config/bigip.conf", 0);
}