FTP db scripts
Dale S. Johnson
Tue Dec 13 20:06:08 CET 1994
FYI, Here are some scripts as we're using them to ftp db's and index them. The PRDB script is a bit more complicated, because PRDB can finish anytime between 3:am and noon EST. #!/usr/local/bin/perl # # import.canet - bring over CANET.db # # $Id: import.canet,v 1.1 1994/12/13 18:59:30 dsj Exp dsj $ # # require "/ra/lib/perl/aftp.pl" ; require "/ra/lib/perl/times.pl" ; umask 2 ; $start = $^T ; chdir "/ra/crons/incoming.canet"; printf STDERR "%s $0 getting the new canet.db...\n", &date_stamp; &aftp( "crcd.canet.ca:/canet/crcd/canet.db" ); &timeline( "ftp canet.ca" ); print `/ra/ripe181/bin/netdbm canet.db` ; &timeline( "netdbm canet.db" ); print `/ra/ripe181/bin/netdbm -c canet.db` ; &timeline( "netdbm -c canet.db" ); print `/bin/rm -f /ra/ripe181/data/d-canet/*` ; print `/bin/mv canet.db* /ra/ripe181/data/d-canet` ; &timeline( "mv canet.db* /ra/ripe181/data/d-canet" ); ------------------ #!/usr/local/bin/perl # # import.prdb - use ftp to check for a new prdb being available. # if there is a new one, then kick off an index, and mark # that this one is the one you've got. # # The prdb program that kicks this process off is ~prdb/bin/prdb_rrdb. # The particular statement that starts the magic is: # date +%y%m%d%H%M%S > /u/ftp/pub/PRDB_TIMESTAMP # # BUGS: This code does not cover the case that a second reindex is # kicked off before the first is finished. # # $Id: import.prdb,v 1.2 1994/12/13 19:05:07 dsj Exp dsj $ # # require "/ra/lib/perl/aftp.pl" ; require "/ra/lib/perl/times.pl" ; umask 2; chdir "/ra/crons/incoming.prdb"; &aftp( "twain.merit.edu:pub/PRDB_TIMESTAMP" ); $new_date = &get_datestamp( "PRDB_TIMESTAMP" ); $last_date = &get_datestamp( "LAST_PRDB_TIMESTAMP" ); if ( $new_date gt $last_date ) { printf "%s $0 getting the new prdb.db...\n", &date_stamp; print `cp PRDB_TIMESTAMP LAST_PRDB_TIMESTAMP`; &aftp( "twain.merit.edu:pub/prdb.db" ); &timeline( "ftp prdb.db" ); print `/ra/ripe181/bin/netdbm prdb.db` ; &timeline( "netdbm prdb.db" ); print `/ra/ripe181/bin/netdbm -c prdb.db` ; &timeline( "netdbm -c prdb.db" ); print `/bin/rm -f /ra/ripe181/data/d-prdb/*` ; print `/bin/mv prdb.db* /ra/ripe181/data/d-prdb` ; &timeline( "mv prdb.db* /ra/ripe181/data/d-prdb" ); } #------------------------------ subroutines ----------------------------- # # Open a file, and return the date stamp within it. # sub get_datestamp { local( $file ) = @_ ; $date = `cat $file`; # 941205140956 if ( $date lt "940102030405" ) { print "error: no date in $file\n"; print "-->$date<--\n"; $date = "0\n"; } chop($date) ; return ($date) ; } #!/usr/local/bin/perl # # Bring a file over via anonymous ftp. # # $Id: aftp.pl,v 1.1 1994/12/13 19:02:53 dsj Exp dsj $ # sub aftp { local ( $remote, $local_file ) = @_; ($host = $remote) =~ s/:.*$// ; ($path = $remote) =~ s/^.*:// ; if ( $path =~ m|/| ) { $path =~ m|^(.*)/([^/]*)$| ; $cd_path = $1 ; $file = $2 ; } else { $file = $path ; $cd_path = ""; } $user = getpwuid( $< ); chop( $this_machine = `hostname` ); $this_machine .= ".ra.net" ; $cmd = "user anonymous $user\@$this_machine\n" ; $cmd .= "cd $cd_path\n" if ($cd_path) ; $cmd .= "get $file $local_file\n" . "quit\n" ; print `echo '$cmd' | ftp -n $host `; # # Should figure some way of checking success here... # } 1; #!/usr/local/bin/perl # # times.pl - format log lines with date/time stamps # # &date_stamp returns "yy-mm-dd hh:mm" # &timeline( "message" ) prints "hh:ss hh:ss message" # # $Id: times.pl,v 1.1 1994/12/13 19:02:53 dsj Exp dsj $ # # sub date_stamp { ($sec, $min, $hour, $mday, $mon, $year) = localtime( $^T ); return( sprintf("%2.2d-%2.2d-%2.2d %2.2d:%2.2d", $year, $mon+1, $mday, $hour, $min )); } sub timeline { local( $msg ) = @_ ; local( $now ) = time ; $last_timeline_call = $^T unless ($last_timeline_call); $total_used = prt_time( $now - $^T ); $last_used = prt_time( $now - $last_timeline_call ); print "$total_used $last_used $msg\n"; $last_timeline_call = $now ; } sub prt_time { local( $secs ) = @_ ; local( $days, $hrs, $min, $rtn); $days = int( $secs / 86400) ; $secs -= $days * 86400 ; $hrs = int( $secs / 3600) ; $secs -= $hrs * 3600 ; $min = int( $secs / 60 ); $secs -= $min * 60 ; if ( $days>0 ) { $rtn = sprintf("%2.2d:%2.2d:%2.2d:%2.2d", $days, $hrs, $min, $secs) } elsif ( $hrs>0 ) { $rtn = sprintf("%2.2d:%2.2d:%2.2d", $hrs, $min, $secs) } else { $rtn = sprintf("%2.2d:%2.2d", $min, $secs) } return( $rtn ); } 1; -------- Logged at Tue Dec 13 22:28:18 MET 1994 ---------
[ rr-impl Archive ]