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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keep connection alive

Status
Not open for further replies.

M626

Programmer
Mar 13, 2002
299
0
0
I am having a problem with this script. I connect to a mapped drive and test against a text file(listDir.txt) if those files listed in the text file are in the directory. if there is a file that is in the directory but not on the list, it get deleted. My problem is the drive become unavailable for a about 30 seconds sometimes because of congestion, is there a way i can have the script retry after so many seconds if it looses connection?

#------Start of Script-------

#!/usr/bin/perl
use File::Basename qw(basename);
use Tie::File;
use File::Copy;

use strict;

my $datafile = 'C:\Temp_83/listDir.txt';
my $datadir = 'T:\DataFiles';

tie my @array, 'Tie::File', $datafile or die "Can't open $datafile: $!";
my %files = map {basename($_) => 1} grep {! /^\s*$/} @array;
untie @array;

open(OUTFILE, "> C:/TEMP_83/DeletedFiles.log") or die "can't open outfile : $!\n";
for (grep {!$files{basename($_)}} glob("$datadir/*")) {
unlink or die "Can't unlink $_: $!";
print OUTFILE "$_\n";

}
 
If it's on a unix machine you can use alarm to start a timer and do something if it hangs or doesn't complete in that time frame. The alarm function doesn't work (or doesn't work well I can't remember which) on windows with activestate.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
it's running on a windows machine.
 
why not just surround the whole script with a while statement and sleep for at the bottom?
$i = 1;
while ($i == 1) {
#Do some stuff and if you have any serious errors that should kill stop the script set $i to anything but 1.
sleep 30;
}


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top