Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (49 sloc) 1.74 KB
#!/bin/sh
#
# https://git.corp.yahoo.com/paranoids/scanmaster/blob/master/scanmaster/helpers/generic-aggregator
#
# Copyright (c) 2008 Yahoo! Inc.
#
# Originally written by Jan Schaumann <jans@yahoo-inc.com> in July 2007.
#
# This script aggregates the data from a full scan into a directory under
# the webservers docroot. It takes three arguments, the one-word name of
# the scan, original input file and a 'start' file.
name=${1}
input=${2}
startfile=${3}
date=$(date +%Y%m%d)
suffix=$(echo ${input} | sed -e "s|.*/||" -e "s|${name}-*||")
prefix=${BASEDIR:-/mnt/scanmaster}/${USER}/chunked/${name}
outdir=${BASEDIR:-/mnt/scanmaster}/${USER}/${name}-not-yet/${date}/${suffix}
(
echo "Aggregating data..."
mkdir -p ${prefix}/final
cp ${input} ${prefix}/final/input
dirs=$(find ${prefix}/* -maxdepth 0 \( ! -name final -and -type d \) -newer ${startfile})
# mutli-line output in 'output', hostnames etc. in 'ok'
find ${dirs} -name hosts_ok -exec cat {} \; | tee ${prefix}/final/output | grep , | sort -u > ${prefix}/final/ok
# cat */*/*/hosts_checked might be too many files for the shell,
# so find(1) them instead.
for filename in $(find ${dirs} \( ! -name 'hosts_ok' -and -name 'hosts_*' -or -name 'exit_*' \)); do
f="${filename##*/hosts_}"
cat ${filename} >> ${prefix}/final/${f}
done
mkdir -p ${outdir}
cp ${prefix}/final/* ${outdir}/
cd ${outdir}
wc -l * | egrep -v "(count|total|start|end)" > count
chmod -R a+rX,g+rw ${outdir}
mkdir -p ${prefix}/.old/${date}
rm -rf ${prefix}/.old/${date}/*
mv ${prefix}/* ${prefix}/.old/${date}/
)
ended=$(date)
host=$(hostname)
echo "Sending mail..."
/usr/sbin/sendmail -t <<EOM
To: ${USER}@yahoo-inc.com
From: ${USER}@yahoo-inc.com
Subject: scanhosts ${name} results from ${date}
${outdir}
EOM