From bcdbd32b5990aad5569fe55bf345bd0ef659249a Mon Sep 17 00:00:00 2001 From: "Gary T. Giesen" Date: Wed, 22 Jul 2026 13:49:41 -0400 Subject: [PATCH] control_rancid, rancid-run: allow -r to be specified multiple times The -r option previously accepted only a single device, and a repeated -r silently kept just the last one (control_rancid overwrote $device on each occurrence). Accumulate the device names instead and filter routers.up against all of them, so several devices can be collected in a single run. Devices found in the same group are collected and committed together; when a group does not contain any of the requested devices it is skipped, as before. rancid-run already passes repeated -r flags through to control_rancid unchanged, so no functional change was needed there. - bin/control_rancid.in: accumulate -r into $device; grep each device into routers.single; skip the group only if none matched. - man/control_rancid.1, man/rancid-run.1: document repeatable -r. - CHANGES: note the change. --- 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 3dff467e..7260397d 100644 --- 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@github with minor syntax adjustment diff --git a/bin/control_rancid.in b/bin/control_rancid.in index 40491479..5c31a5cb 100644 --- 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 5075c079..48c08474 100644 --- 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 de425e97..10b0e9bc 100644 --- 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 -- 2.52.0