File: rancid-cgi.cron

package info (click to toggle)
rancid 3.9-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,484 kB
  • sloc: sh: 2,611; ansic: 1,683; makefile: 354; exp: 185
file content (37 lines) | stat: -rw-r--r-- 891 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh

#
# /etc/cron.hourly/rancid-cgi: update rancid-cgi config files from rancid configuration
#

# destination filenames to be created
CLOGINRC=/etc/rancid/cloginrc
ROUTERDB=/etc/rancid/router.db
OWNER='www-data:www-data'

# this is an awk regex to select devices from router.db for matching vendors
VENDOR_REGEX='cisco|juniper|foundry'

# config source
RANCID_DIR=`awk -F: '$1 ~ /^rancid$/ { print $6 }' /etc/passwd`

if [ ! -d ${RANCID_DIR} ]
then
    echo "Cannot determine rancid home directory, exiting." 2>&1
    exit 1
fi

if [ -f ${RANCID_DIR}/.cloginrc ]
then
    cp ${RANCID_DIR}/.cloginrc ${CLOGINRC}
    chown ${OWNER} ${CLOGINRC}
    chmod 640 ${CLOGINRC}
fi

if (wc -l ${RANCID_DIR}/*/router.db 2>&1 >/dev/null)
then
    awk -F: "\$2 ~ /${VENDOR_REGEX}/ { print \$0 }" ${RANCID_DIR}/*/router.db > ${ROUTERDB}
    chown ${OWNER} ${ROUTERDB}
    chmod 640 ${ROUTERDB}
fi