[rancid] Re: Adding version tags into CVS/config files

Lance Vermilion rancid at gheek.net
Tue Sep 26 16:52:54 UTC 2006


John,

The only thing I can come up with is __FILE__ has the value of 
"/apps/rancid/bin/rancid" and the s/bin\///g removes the bin/ portion. 
For some reason the path in __FILE__ (/apps/rancid/bin/) gets carried on
as "/apps/rancid/".

The fix for this was to just alter the regex to account for that.
old:      $File =~ s/bin\///g;
new:      $File =~ s/^.*bin\///g;

It now works with rancid-run -r <device> and rancid-run <group>.

Thx for validating it wasn't a rancid error.

For any of you that would like to have your config files to contain the 
version of the rancid scripts that collected the device info you can get 
the file at http://www.gheek.net/scripts/perl/rancid-psvadd_pl.txt

The file versions are the files that make up the core of rancid to my 
knowledge (rancid-run, rancid-fe, control_rancid, par, *rancid, *login).
The *login and *rancid files will change based on which file is needed
by that script.

Let me know if you run into any issue with this.

Example of what it adds to the file.

!RANCID-CONTENT-TYPE: cisco-cat
!
!RANCID-SCRIPT-TYPE: [rancid-fe.in (v 1.37)]
!RANCID-SCRIPT-TYPE: [rancid-run.in (v 1.32)]
!RANCID-SCRIPT-TYPE: [control_rancid.in (v 1.76)]
!RANCID-SCRIPT-TYPE: [par.in (v 1.11)]
!RANCID-SCRIPT-TYPE: [clogin.in (v 1.94)]
!RANCID-SCRIPT-TYPE: [cat5rancid.in (v 1.45)]


I have also added it inline here as well along with the rancid.conf changes
that are needed.

<FILE: etc/rancid.conf>
# Set PSV to NO to disable the print script versions
# Default is NO even if commented out.
PSV=YES; export PSV

<FILE: rancid-psvadd.pl>
#!/usr/bin/perl -w
#Author:  Lance Vermilion
#Purpose: Add PrintScriptVersion to all files
#Note:    This file must be run with the 
#         environmental vars from rancid.confs
#
#Instructions:
#         su - <rancid-user>
#         cd <rancid bin dir> (ex. /usr/local/rancid)
#         . etc/rancid.conf
#         PSVadd.pl
#         New files will be called ".new". Just 
#         move the old file or nename the old
#         files to something other than the default
#         names. Then you can remove the .new from
#         the filename that this script created.
#
#         You can do it simply like this.
#         for i in `ls -1 | egrep -v ".new|hpuifilter|control_rancid|rancid-fe|rancid-run|rancid-cvs|cgi|par|.*login.*"`
#         do
#         mv $i <some archive location>
#         done
#
#         Make sure to test your new perl files to 
#         sure they have proper syntax.
#         for i in `ls -1 | egrep -v "hpuifilter|control_rancid|rancid-fe|rancid-run|rancid-cvs|cgi|par|.*login.*"`
#         do
#         perl -c $i
#         done
#
#         Make your ".new" files lose the .new and 
#         set the ownership.
#         for i in `ls -1 | egrep -v "hpuifilter|control_rancid|rancid-fe|rancid-run|rancid-cvs|cgi|par|.*login.*"`
#         do
#         chmod 750 $i
#         I=`echo $i | sed 's/.new//g'`
#         mv $i $I
#         done
##################################################

$dir = $ENV{"BASEDIR"} . '/../bin/';
opendir my $dh, $dir or die $!;
my @files = grep {$_ !~ /hpuifilter|control_rancid|rancid-fe|rancid-run|rancid-cvs|cgi|par|.*login.*|\.|\.\./} readdir $dh;
   close $dh;
for my $file (@files)
{
  $file = $ENV{"BASEDIR"} . '/../bin/' . $file;
  open(FILE, "$file") or warn "$file not able to be opened:$!\n";
  open(NEWFILE, ">$file.new") or warn "$file not able to be opened:$!\n";
  while (<FILE>)
  { 
    if (/.*system\s\"(.*)-t.*/)
    {
      $loginfile = $1;
      $loginfile =~ s/\s+//g;
      chomp $loginfile;
    }
  
    if (/RANCID-CONTENT-TYPE/)
    {
      print NEWFILE '
# Print Script Versions
# This will print out the versions of the scripts
# that are the core of rancid and the version of
# this script.
sub PrintScriptVersions()
{
  if (defined($ENV{"PSV"}) && $ENV{"PSV"} =~ /yes/i)
  {
    my @files = (\'rancid-fe\', \'rancid-run\', \'control_rancid\', \'par\', '; print NEWFILE "\'$loginfile\'" ; print NEWFILE ', __
FILE__);
    for my $file (@files)
    { 
      $file =~ s/^.*bin\///g;
      $file = $ENV{"BASEDIR"} . \'/../bin/\' . $file;
      open(FILE, "$file") or warn "$file not able to be opened:$!\n";
      while (<FILE>)
      {
        if ( /^##\s\$Id:\s(.*)\s(\d+){4}\/.*\sExp\s\$$/ )
        {
          my ($script, $version) = split(/,/, $1);
          chomp ($version, $script);
          ProcessHistory("","","","!RANCID-SCRIPT-TYPE: [$script ($version)]\n");
        }
      }
      close (FILE);
    }
    ProcessHistory("","","","!\n");
  }
  else
  {
    ProcessHistory("","","","!\n");
  }
}' . "\n\n";
      print NEWFILE;
      print NEWFILE 'PrintScriptVersions();' . "\n";
    }
    else
    {
      print NEWFILE;
    }
  }
close(FILE);
close(NEWFILE);
}

-- 

-Lance <rancid at gheek.net>

On Tue, Sep 26, 2006 at 10:04:55AM +0000, john heasley wrote:
> Tue, Sep 26, 2006 at 01:46:26AM -0700, Lance Vermilion:
> > Hey all,
> > 
> > Anyone got an idea why this is happening?
> > 
> > I have this script that I was talking about working if I run it with rancid-run -r <device>. 
> > 
> > If I run it with rancid-run and let it spin through the devices in the devicelist I end up with the following errors.
> > 
> > Trying to get all of the configs.
> > File: /apps/rancid/var/../bin//apps/rancid/cssrancid not able to be opened:No such file or directory
> > File: /apps/rancid/var/../bin//apps/rancid/rancid not able to be opened:No such file or directory
> 
> that is not a rancid error.  perhaps from your shell or perl?





More information about the Rancid-discuss mailing list