I would like to parse the contents of a text file. This text file is built from a sql query.
/text_file.txt
Contents of text_file.txt would be:
0123456789YYYYMMDDHHMMSS
0123456789YYYYMMDDHHMMSS
0123456789YYYYMMDDHHMMSS
each line will have a unique 'YYYYMMDDHHMMSS'
I will need to append .tar to each line and rcp to another server.
But, I will need to use the YYYYMMDD to specify target and source directory for the rcp command.
I also need to break up the YYYYMMDD into /YYYY/MM/DD/ as the file is stored this way in the filesystem (/YYYY/MM/DD/012YYYYMMDDHHMMSS.tar
Then use this to copy the file using rcp, then changing the permissions once it has copied to the other server.
For example:
rcp -p file.tar user@host:file.tar
rsh -l user host "chmod 755 file.tar"
I am new to Perl. With some help, I have been able to piece together a way to open the text_file.txt and make the filename.tar with appropriate source/destination directories (they are the same).
I need to add a subroutine to rcp and change permissions (as noted above).
Here is what I have so far:
Any help would be greatly appreciated!
Thanks!
/text_file.txt
Contents of text_file.txt would be:
0123456789YYYYMMDDHHMMSS
0123456789YYYYMMDDHHMMSS
0123456789YYYYMMDDHHMMSS
each line will have a unique 'YYYYMMDDHHMMSS'
I will need to append .tar to each line and rcp to another server.
But, I will need to use the YYYYMMDD to specify target and source directory for the rcp command.
I also need to break up the YYYYMMDD into /YYYY/MM/DD/ as the file is stored this way in the filesystem (/YYYY/MM/DD/012YYYYMMDDHHMMSS.tar
Then use this to copy the file using rcp, then changing the permissions once it has copied to the other server.
For example:
rcp -p file.tar user@host:file.tar
rsh -l user host "chmod 755 file.tar"
I am new to Perl. With some help, I have been able to piece together a way to open the text_file.txt and make the filename.tar with appropriate source/destination directories (they are the same).
I need to add a subroutine to rcp and change permissions (as noted above).
Here is what I have so far:
Code:
#! /usr/bin/perl -w
sub copyDSTfile($);
# rsh user and host information
my $rshUser = "user";
my $rshHost = "192.168.1.1";
# destination paths
my $baseDSTpath = "/directory";
my $DSThost = "host";
my $infh = "";
my $name;
my $filepath;
my $filename;
my $fileyear;
my $filemonth;
my $fileday;
my $infile = "./text_file.txt";
# -----------------------------------------
# open files
open ($infh, "<".$infile) || die "Couldn't open $infile for reading!";
# -----------------------------------------
# start loop
while (<$infh>)
{
$name = $_;
chomp $name;
$fileyear = substr($name, 10, 4);
$filemonth =substr($name, 14, 2);
$fileday = substr($name, 16, 2);
$filename = $baseDSTpath."/".$DSThost."/".$fileyear."/".$filemonth."/".$fileday."/".$name.".tar";
logDebug($filename."\n");
Any help would be greatly appreciated!
Thanks!