[rancid] Re: /tmp/.networking.run.lock exists

Chris Moody cmoody at qualcomm.com
Fri Jan 12 20:23:48 UTC 2007


Good idea to split them if this is the case.  I have defined groups as well.

But, I also wrote a perl util that I run on a cron to do housekeeping 
and cleanup in case the rancid proc barfs and leaves .lock files.

I make -0- claim of being a "good" coder, but the thing works and I'm 
happy.  YMMV.

Cheers,
-Chris


Pena, Antonio wrote:
> Hello Justin
> 
> Thank you so much, I think could be the issue, I recently added a bunch
> of additional routers, so maybe that is happening, I will try this to
> see that helps
> 
> Thank you all
> 
> Antonio


#!/usr/bin/perl -w
#
# I need to do housekeeping so the rancid process works more smoothly
# This includes:
#                       - /tmp/.*lock files
#                       - .ssh/known_hosts files (firewall backups - in 
case of failover)
#                       - probably more to come...
#
###################
# Here ya go Samy #
###################
use strict;

####################################################
# Initialize Mail::Sender so we can e-mail results #
####################################################
use Mail::Sender;

####################
# Sweet File Utils #
####################
use File::Copy;
# stat(); produces the following 13-element array
# [0]$dev - device name
# [1]$ino - i-unit number
# [2]$mode - access permissions
# [3]$nlink - number of intercommections
# [4]$uid - owner identificator
# [5]$gid - group identificator
# [6]$rdev - device type
# [7]$size - file size in bytes
# [8]$atime - date of last call
# [9]$mtime - date of last modification
# [10]$ctime - date of last status change
# [11]$blksize - block size on disk
# [12]$blocks - number of blocks in file.

##########################################################
# E-mail address to mail the output report to by default #
# This eventually needs to be a command line flag rather #
# than a static variable                                 #
##########################################################
my $emailaddy="INSERT-YOUR-EMAIL-HERE";
my $fromaddress="INSERT-A-VALID-FROM-ADDRESS-HERE";
my $mailserver="INSERT-A-VALID-MAILSERVER-HERE";

###########################################
###########################################
########## DEFINE VARIABLES HERE ##########
###########################################
###########################################
my $lockdir="/tmp";
#my @LOCKS=`ls -a /tmp/.*lock*`;
my @LOCKS=`ls -a /tmp/ | grep lock`;
my $hostsfile="PATH-TO-RANCID-USER-DIR/.ssh/known_hosts";
my $DATE=`date +%m-%d-%y_%H%M%S`;
my $HOSTNAME=`hostname`;
chomp($HOSTNAME);

#####################################
#  Toggle this to enble debugging   #
#####################################
my $debug="0";          # 1 = on , 0 = off



if ($debug eq "1"){print "\$emailaddy = $emailaddy\n";};
if ($debug eq "1"){print "\$fromaddress = $fromaddress\n";};
if ($debug eq "1"){print "\$mailserver = $mailserver\n";};
if ($debug eq "1"){print "\$hostsfile = $hostsfile\n";};

# remove any stale .lock files from /tmp
# Ex> /tmp/.firewall-admins.run.lock
if (@LOCKS){
         if ($debug eq "1"){print "\@LOCKS = @LOCKS\n";};
         foreach my $i (@LOCKS){
                 chomp ($i);
                 if ($debug eq "1"){print "\$i = $i\n";};
                 unlink ("$i") || die "Can't unlink file $i";
                 #############################
                 # E-MAIL COPY OF THE REPORT #
                 #############################
                 my $sender = new Mail::Sender {
         i               smtp => "$mailserver",
                         from => "$fromaddress",
                         on_errors => undef,
                         };
                 $sender->Open({
                         to => "$emailaddy",
                         subject => "$HOSTNAME: Lockfile for $i removed 
- $DATE",
                         });
                 $sender->Close();
                 if ($debug eq "1"){print "\$sender = $sender\n";};
                 } # Close foreach
         } # Close if
# remove .known_hosts file from ~/.ssh/
# This will allow firewalls to get backed up if they fail over
if (-f "$hostsfile") {
         if ($debug eq "1"){print "\$hostsfile = $hostsfile\n";};
         unlink ("$hostsfile") || die "Can't unlink file $hostsfile";
                 #############################
                 # E-MAIL COPY OF THE REPORT #
                 #############################
                 my $sender = new Mail::Sender {
                         smtp => "$mailserver",
                         from => "$fromaddress",
                         on_errors => undef,
                         };
                 $sender->Open({
                         to => "$emailaddy",
                         subject => "$HOSTNAME: Known_hosts file removed 
- $DATE",
                         });
                 $sender->Close();
                 if ($debug eq "1"){print "\$sender = $sender\n";};
         } # Close if



More information about the Rancid-discuss mailing list