Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable interpolation - help

Status
Not open for further replies.

netrookie

Technical User
Jul 6, 2003
29
US
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 found out my problem. It works now. I used qx and build the filename from that.

my $datecnf = qx(date '+%Y%m%d'."cnf");

# Build system command to execute
my $get_cmd = "scp $hostname:/home/y/etc/my.cnf $datecnf";

 
Another way that doesn't involve calling an external utility:

Code:
use POSIX qw(strftime);
my $datecnf=strftime "%Y%m%d",localtime;

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top