So far I have this script running, but what I want to do is create a timestamped file, getting from date and then call it for example 20100319.cnf
I am having problems though trying to get the date part to append to the ".cnf" name.
I tried using "." to concatenate it. Apparently I don't understand how to use this properly.
Please advise. Thanks.
Here's the code:
#!/usr/local/bin/perl -w
use warnings;
use strict;
use POSIX qw( strftime );
# Using ARGV (for input for hostname
unless ( @ARGV == 1 )
{
die "Usage: $0 <hostname>\n";
}
my ( $hostname ) = @ARGV;
# Create date stamped cnf file
my $date = `date '+%Y%m%d'`;
# Build system command to execute
#my $get_cmd = "scp $hostname:/home/y/etc/my.cnf my2.cnf";
my $get_cmd = "scp $hostname:/home/y/etc/my.cnf $date"."cnf";
# Run the command
my $rc = system ($get_cmd);
if ( $rc == 0 )
{
# everything went well, as far as perl is concerned.
}
elsif ( $rc == -1 )
{
# couldn't even start the program; look in $! to see why.
}
else
{
my $exit_signal = $rc & 0x7f;
my $has_coredump = $rc & 0x80;
my $exit_value = $rc >> 8;
# report the above as you like. See 'perlfunc' man page on system() call.
}
I am having problems though trying to get the date part to append to the ".cnf" name.
I tried using "." to concatenate it. Apparently I don't understand how to use this properly.
Please advise. Thanks.
Here's the code:
#!/usr/local/bin/perl -w
use warnings;
use strict;
use POSIX qw( strftime );
# Using ARGV (for input for hostname
unless ( @ARGV == 1 )
{
die "Usage: $0 <hostname>\n";
}
my ( $hostname ) = @ARGV;
# Create date stamped cnf file
my $date = `date '+%Y%m%d'`;
# Build system command to execute
#my $get_cmd = "scp $hostname:/home/y/etc/my.cnf my2.cnf";
my $get_cmd = "scp $hostname:/home/y/etc/my.cnf $date"."cnf";
# Run the command
my $rc = system ($get_cmd);
if ( $rc == 0 )
{
# everything went well, as far as perl is concerned.
}
elsif ( $rc == -1 )
{
# couldn't even start the program; look in $! to see why.
}
else
{
my $exit_signal = $rc & 0x7f;
my $has_coredump = $rc & 0x80;
my $exit_value = $rc >> 8;
# report the above as you like. See 'perlfunc' man page on system() call.
}