[rancid] [PATCH] control_rancid, rancid-run: allow -r to be specified multiple times

Gary T. Giesen ggiesen at giesen.me
Tue Aug 18 02:59:40 UTC 2026


The -r option to rancid-run/control_rancid currently accepts a single
device.  Passing -r more than once silently keeps only the last device,
because control_rancid overwrites $device on each occurrence of the flag.

This patch accumulates the device names and filters routers.up against
all of them, so several specific devices can be collected in one run
without collecting the whole group.  Devices in the same group are
collected and committed together; a group that contains none of the
requested devices is skipped, as before.  A single -r behaves exactly as
it does today, so existing usage and cron jobs are unaffected.

rancid-run already passes repeated -r flags through to control_rancid
untouched, so the change is confined to control_rancid; rancid-run needed
no code change.  Man pages and CHANGES are updated.

I've also opened this as a GitHub PR for convenience:
  https://github.com/haussli/rancid/pull/80

Patch against current master (commit 7dc63e64) inline below and attached
as a git-am-able patch.

---
CHANGES               | 4 ++++
bin/control_rancid.in | 13 ++++++++-----
man/control_rancid.1  | 4 +++-
man/rancid-run.1      | 3 +++
4 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/CHANGES b/CHANGES
index ..
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,8 @@
3.14.99
+     control_rancid, rancid-run: allow -r to be specified multiple times to
+     collect several devices in one run, committing per-group devices
+     together - Gary T. Giesen
+
      iosxr.pm: filter oscillating license timestamps - thezoggy at github with
      minor syntax adjustment

diff --git a/bin/control_rancid.in b/bin/control_rancid.in
index ..
--- a/bin/control_rancid.in
+++ b/bin/control_rancid.in
@@ -102,8 +102,8 @@ if [ $# -ge 1 ] ; then
          ;;
      -r)
          shift
-         # next arg is the device name
-         device="$1"
+         # next arg is a device name; -r may be given multiple times
+         device="${device:+$device }$1"
          shift
          ;;
      --)
@@ -549,12 +549,15 @@ if [ ! -s routers.up ] ; then
     exit;
fi

-# if a device (-r) was specified, see if that device is in this group
+# if device(s) (-r) were specified, see if those devices are in this group
if [ "X$device" != "X" ] ; then
     trap 'rm -fr $TMP $DIR/routers.single;' 1 2 15
     devlistfile="$DIR/routers.single"
-    grep -i "^$device\;" routers.up > $devlistfile
-    if [ $? -eq 1 ] ; then
+    : > $devlistfile
+    for dev in $device ; do
+     grep -i "^$dev\;" routers.up >> $devlistfile
+    done
+    if [ ! -s $devlistfile ] ; then
      exit;
     fi
else
diff --git a/man/control_rancid.1 b/man/control_rancid.1
index ..
--- a/man/control_rancid.1
+++ b/man/control_rancid.1
@@ -63,8 +63,10 @@ may be specified multiple times.
.\"
.TP
.B \-r device_name
-Specify the name, as it appears in the router.db, of a particular device
+Specify the name, as it appears in the router.db, of a particular device
to collect and generate diffs for.  The device must be marked "up".
+.B \-r
+may be specified multiple times to collect several devices in a single run.
.sp
The
.B \-r
diff --git a/man/rancid-run.1 b/man/rancid-run.1
index ..
--- a/man/rancid-run.1
+++ b/man/rancid-run.1
@@ -92,6 +92,9 @@ Run rancid for a single device,
should be name, as it appears in a group's router.db.  The device must be
marked "up".  If a group is not specified on the command-line, rancid will
be run against any group in which the device_name appears.
+.B \-r
+may be specified multiple times to collect several devices; those found in
+the same group are collected and committed together in that group's run.
.sp
The
.B \-r

Thanks,
Gary T. Giesen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.shrubbery.net/pipermail/rancid-discuss/attachments/20260817/02060471/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-control_rancid-rancid-run-allow-r-to-be-specified-mu.patch
Type: text/x-diff
Size: 3733 bytes
Desc: not available
URL: <http://www.shrubbery.net/pipermail/rancid-discuss/attachments/20260817/02060471/attachment.patch>


More information about the Rancid-discuss mailing list