View difference between Paste ID: UUZy0tWX and Dn2FfijW
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/bash
2
3
# usage: ./mass_command <computer(s)> <command>
4
5
# path that is per-computer
6-
COMP_PATH='/localdisk/nbook/boinc';
6+
COMP_PATH='/localdisk/boinc';
7
8
#---
9
# replace ',' with ' ' so that we can easily iterate
10
computers=`echo $1 | sed -e 's/,/ /g'`
11
12
# these are the computer names for my network, for demonstration:
13
all_majors='tabletop blake macomb cascade phelps colden porter marcy seward nye sawteeth'
14
all_minors='skylight armstrong cliff gothics hough haystack iroquois colvin panther algonquin wright marshall redfield whiteface'
15
all_servers='cycle1 cycle2 cycle3'
16
all_clients="$all_majors $all_minors"
17
all_computers="$all_servers $all_clients"
18
19
# if one of these matches, use that list instead of keyword; switch should have been used here...
20
if [ "$computers" == "all" ]
21
then
22
    computers=$all_computers
23
fi
24
if [ "$computers" == 'majors' ]
25
then
26
    computers=$all_majors
27
fi
28
if [ "$computers" == 'minors' ]
29
then
30
    computers=$all_minors
31
fi
32
if [ "$computers" == 'clients' ]
33
then
34
    computers=$all_clients
35
fi
36
if [ "$computers" == 'servers' ]
37
then
38
    computers=$all_servers
39
fi
40
41
# remove $1 from $@ -> $args
42
args=`echo $@ | sed -e "s/$1 //"`
43
44
# iterate over $computers and run $args in $COMP_PATH
45
# NOTE: this makes '.' mean something different in argument to this program vs. when calling this program!
46
for C in $computers
47
do
48
    echo "Running '$args' on $C:"
49
    ssh $C "cd $COMP_PATH; $args"
50
done