Thank you Again . it worked
I am Relatively very new to Perl scripting . I dont have help at work .
This forum and you are a great help to me .
---------- Post updated 04-26-13 at 01:31 PM ---------- Previous update was 04-25-13 at 04:07 PM ----------
Need help again . Below are the 2 things i need to this script
- This script creates an output to output.log . when i run again it should create a backup file example
output.log.<date>
with timestamp
2. Check the difference of the old file and the new file and report it if there is an update .
I have added the below script , the second script is an example of creating a backup file with timestamp but i dont know how to club that script to the 1st script
#!/usr/bin/perl -w
use Net::FTP;
my @str=("files.txt");
open(IN, "<files.txt");
open(OUT, ">output.log");
while($line=<IN>)
{
chomp($line); # Remove newline from end of string
push(@str, $line); # Add string to end of @str array
}
$ftp = Net::FTP->new("hostname");
$ftp->login('user', 'password');
$ftp->cwd("path");
$ftp->binary;
my @filenames=$ftp->ls();
print " Total files:", $#filenames + 1, "\n";
$match=0;
foreach (@filenames)
{
for my $s(@str)
{
if(index($_, $s) >= 0)
{
print OUT "$_", " ", $ftp->size($_),
# print $_, " Size:[", $ftp->size($_), "]",
# " Mtime ", scalar(localtime($ftp->mdtm($_))),
"\n";
$match++;
copy ("output.log", "output.log".$date."");
}
}
}
if($match == 0) { print "No files matched\n"; }
$ftp->quit();
use File::Copy;
my (undef,undef,undef,$mday,$mon,$year,undef,undef,undef) = localtime;
$year += 1900;
$mon += 1;
$date = sprintf "%02d/%02d/%04d", $mon, $mday, $year;
#copy (" output.log","output.log".$date."");