From 39beb2813d1d4dadff526699e48ab0852d4506c0 Mon Sep 17 00:00:00 2001 From: Andrew DeFaria Date: Tue, 31 Jan 2017 18:22:39 -0800 Subject: [PATCH] Misc changes --- bin/allmach.sh | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ bin/bigfiles.pl | 5 ++- 2 files changed, 111 insertions(+), 2 deletions(-) create mode 100755 bin/allmach.sh diff --git a/bin/allmach.sh b/bin/allmach.sh new file mode 100755 index 0000000..d4a9ba5 --- /dev/null +++ b/bin/allmach.sh @@ -0,0 +1,108 @@ +#!/bin/bash +. _DEBUG.sh + +################################################################################ +# +# File: allmach +# Description: Runs an arbitrary command on all machines +# Author: Andrew@DeFaria.com +# Created: Fri Apr 30 14:17:40 PDT 1999 +# Language: Bash Shell +# Modifications:Added trapping of INT so that you can abort a non-responding +# machine. +# +# (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved +# +################################################################################ +# Set me to command name +me=$(basename $0) + +if [ -f ~/.rc/set_colors ]; then + source ~/.rc/set_colors +fi + +# Set adm_base +adm_base=${adm_base:-/opt/clearscm} + +# Set machines +machines=${machines:-$adm_base/data/machines} + +if [ "$1" = "-f" ]; then + shift + machines="$1" + shift +fi + +if [ "$1" = "-r" ]; then + root_ssh=true + shift +fi + +if [ ! -f $machines ]; then + echo "Unable to find $machines file!" + exit 1; +fi + +function trap_intr { + echo "${machines[i]}:$cmd interrupted" + echo -e "$RED(A)bort$NORMAL $me or $YELLOW(C)ontinue$NORMAL with next machine? \c" + read response + typeset -l response=$response + + case "$response" in + a|abort) + echo "Aborting $me..." + exit + ;; + esac + echo "Continuing on with the next machine..." +} # trap_intr + +# Build up data arrays. Note this is done because if we ssh while in a pipe +# Sun will not allow a simple ssh with no command (boo!) +# Column 1 Machine name +# Column 2 Model +# Column 3 OS Version +# Column 4 ClearCase Version (if applicable) +# Column 5 Owner (if known) +# Column 6 Usage (if known) +#oldIFS=$IFS +#IFS=":" +declare -i nbr_of_machines=0 +#sed -e "/^#/d" $machines | +while read machine; do + machines[nbr_of_machines]=$machine + let nbr_of_machines=nbr_of_machines+1 +done < <(grep -v ^# $machines) + +if [[ -z "$@" ]]; then + cmd="# ${YELLOW}<- ssh into machine$NORMAL" +else + cmd="$@" +fi + +# This loop executes the command +trap trap_intr INT +declare -i i=0 +while [ $i -lt $nbr_of_machines ]; do + export currmachine=${machines[i]} + # Execute command. Note if no command is given then the effect is to + # ssh to each machine. + echo -e "${CYAN}${machines[i]}$NORMAL\c" + echo -e ":$cmd" + if [ $# -gt 0 ]; then + if [ "$root_ssh" = "true" ]; then + ssh ${machines[i]} -n -l root "$cmd" + else + ssh ${machines[i]} -n "$cmd" + fi + else + if [ "$root_ssh" = "true" ]; then + ssh ${machines[i]} -l root + else + ssh ${machines[i]} + fi + fi + let i=i+1 +done +trap - INT diff --git a/bin/bigfiles.pl b/bin/bigfiles.pl index ec9f2a2..1918de1 100755 --- a/bin/bigfiles.pl +++ b/bin/bigfiles.pl @@ -43,7 +43,7 @@ sub Bigfiles { foreach (@dirs) { next if !-d "$_"; - my $cmd = "find \"$_\" -xdev -type f -size +$size -exec ls -lLGQ {} \\;"; + my $cmd = "find \"$_\" -xdev -type f -size +$size -exec ls -lLG {} \\;"; my @lines = `$cmd`; foreach (@lines) { @@ -51,7 +51,8 @@ sub Bigfiles { my %info; - if (/\S+\s+\d+\s+(\S+)\s+(\d+).*\"\.\/(.*)\"/) { + #if (/\S+\s+\d+\s+(\S+)\s+(\d+).*\"\.\/(.*)\"/) { + if (/\S+\s+\d+\s+(\S+)\s+\S+ \S+\s+(\d+)\s+\S+\s+\d+\s+\S+\s+(\S+)/){ $info {user} = $1; $info {filesize} = $2; $info {filename} = $3; -- 2.17.1