Changeset 2823 for trunk/locker/sbin


Ignore:
Timestamp:
Feb 23, 2017, 12:19:45 AM (8 years ago)
Author:
andersk
Message:
rpm-master.sh, rpmlist.sh: Improve shell hygiene
Location:
trunk/locker/sbin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/locker/sbin/rpm-master.sh

    r2274 r2823  
    1 #!/bin/sh
     1#!/bin/bash
     2set -eu -o pipefail
    23
    34export LC_ALL=C
     
    89
    910echo "Cleaning up environment..."
    10 rm -rf *.rpmlist *.diff rpmlist.master missing.rpms
     11rm -rf ./*.rpmlist ./*.diff rpmlist.master missing.rpms
    1112
    12 servers=`finger @scripts-director.mit.edu | grep "\->" | grep EDU | awk '{print $2}' | cut -d: -f1 | sort | uniq`
     13servers=$(finger @scripts-director.mit.edu | grep "\->" | grep EDU | awk '{print $2}' | cut -d: -f1 | sort | uniq)
    1314
    1415for server in $servers; do
    1516    echo "Connecting to $server..."
    16     { ssh $server /mit/scripts/sbin/rpmlist.sh 2>&1 >&3 | grep -Fxv 'If you have trouble logging in, see http://scripts.mit.edu/faq/41/.'; } 3>&1 >&2
     17    { ssh "$USER@$server" /mit/scripts/sbin/rpmlist.sh 2>&1 >&3 | { grep -Fxv 'If you have trouble logging in, see http://scripts.mit.edu/faq/41/.' || [ $? -eq 1 ]; }; } 3>&1 >&2
    1718done
    1819
    1920echo "Creating master package list..."
    20 cat *.rpmlist | sort | uniq > rpmlist.master
     21cat ./*.rpmlist | sort | uniq > rpmlist.master
    2122
    2223echo "Comparing scripts servers to overall rpm list..."
    2324touch missing.rpms
    2425for server in *.rpmlist; do
    25     diff -U3 $server rpmlist.master > $server.diff
    26     serverPretty=`basename $server .rpmlist`
     26    diff -U3 "$server" rpmlist.master > "$server.diff" || :
     27    serverPretty=$(basename "$server" .rpmlist)
    2728    echo "Server $serverPretty is missing:" >> missing.rpms
    28     grep "^+[^+]" $server.diff | cut -b 1 --complement >> missing.rpms
     29    grep "^+[^+]" "$server.diff" | cut -b 1 --complement >> missing.rpms
    2930    echo >> missing.rpms
    3031done
    3132
    32 if [ `egrep -c -v '(missing)|(^$)' missing.rpms` -gt 0 ]; then
     33if egrep -qv '(missing)|(^$)' missing.rpms; then
    3334    echo "Sending email..."
    34     cat missing.rpms | mail -s "scripts.mit.edu servers are out of sync" root@scripts.mit.edu
     35    mail -s "scripts.mit.edu servers are out of sync" root@scripts.mit.edu < missing.rpms
    3536else
    3637    echo "No email needs to be sent! scripts.mit.edu is up to date."
  • trunk/locker/sbin/rpmlist.sh

    r2274 r2823  
    11#!/bin/sh
     2set -eu
    23
    34export LC_ALL=C
    45
    56copyTo='/mit/scripts/cron_scripts/rpm-sync/'
    6 packages=`mktemp --tmpdir rpmlist.XXXXXX`
    7 rpm -qa --queryformat '%{NAME}.%{ARCH}\n' | sort | uniq > $packages
     7packages=$(mktemp --tmpdir rpmlist.XXXXXX)
     8rpm -qa --queryformat '%{NAME}.%{ARCH}\n' | sort | uniq > "$packages"
    89
    9 host=`hostname`
     10host=$(hostname)
    1011extension='.rpmlist'
    1112file="$copyTo/$host$extension"
    12 mv $packages $file
     13mv "$packages" "$file"
Note: See TracChangeset for help on using the changeset viewer.