#!/usr/local/bin/perl -w ###################################################################### +#################################### # + # # Program: GetDCBillingsFiles + # # + # # Description: Programs collects DC billings files from all the serv +ers located at the DC. This # # script is NOT intended to be a production application +. # # + # # Date: 12/27/03 + # # + # ###################################################################### +#################################### use strict; use threads; # Define global variables for program. my @locations = (); my @ftp_sessions = (); my $INTERVAL = 5; my $ACTIVE = 1; my $INACTIVE = 0; ###################################################################### +#################################### # + # # Subroutine: monitor_ftp + # # + # # Description: Subroutine collects information about active FTP sess +ions. # # + # ###################################################################### +#################################### sub monitor_ftp() { my $nbr = 0; my $status = 'status'; my $active_sessions = 0; sleep 1; print "Monitoring FTP sessions ... \n\n\n"; #printf "Sessions status <%d> and location <%s>\n", $ftp_sessions[ +0]->{status}, $ftp_sessions[0]->{loc}; do { my $session; $active_sessions = 0; for $session (@ftp_sessions) { $active_sessions += 1; $nbr++; } print "Active Sessions: $active_sessions\n"; # Check the list size and exit if all threads are complete. if ($active_sessions > 0) { # Monitor the sessions at fixed intervals. sleep $INTERVAL; } } until $active_sessions == 0; } ###################################################################### +#################################### # + # # Subroutine: start_ftp + # # + # # Description: Subroutine starts FTP sessions to collect data from l +ocations. # # + # ###################################################################### +#################################### sub start_ftp($$) { my ($nbr, $location) = @_; my $id = threads->self->tid; printf "FTP session: <%d> <%s>\n", $id, $location; $ftp_sessions[$nbr] = { status => 1, loc => $location }; ############# Insert FTP commands here ######################## my $time_delay = $id*5; sleep $time_delay; ############# Insert FTP commands here ######################## # Session complete. Reset the status and exit the session. $ftp_sessions[$nbr]{status} = 0; printf "Session <%d> complete.\n", $id; } ###################################################################### +#################################### # + # # Main Routine + # # + # ###################################################################### +#################################### $locations[0] = "awd1"; # Loop through the locations, starting a process to extract the data r +equired from each DC. my $loc = 0; my $nbr = 0; foreach $loc (@locations) { # Use threads to manage the FTP sessions. $ftp_sessions[$nbr] = threads->create("start_ftp", $nbr, $loc); $nbr++; } monitor_ftp(); sleep 40;
In reply to data structure question by mjmaresca
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |