-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsshexec
executable file
·57 lines (45 loc) · 1.11 KB
/
sshexec
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
usage() {
cat <<EOS >&2
Usage:
`basename $0` [-p npasswords] [-u username] hostsfile command
Options:
-p npasswords number of passwords to try (5 top)
-u username username to pass to ssh
Arguments:
hostsfile file name holding a list of servers to connect to.
Use - for standard input
command command to execute
EOS
exit 1
}
while getopts :p:u: opt; do
case $opt in
p) npasswords=$OPTARG
[ $npasswords -lt 1 -o $npasswords -gt 5 ] && usage;;
u) useropt="-l $OPTARG";;
?) usage;;
esac
done
shift `expr $OPTIND - 1`
[ $# -lt 2 ] && usage
[ -z "$npasswords" ] && npasswords=1
input=$1; shift
cmd=$@
[ -z "$input" ] && input=-
. ./feedpass.inc
n=1
while [ $n -le $npasswords ]; do
read -s -p "Password[$n]: " password$n < /dev/tty; echo > /dev/tty
n=`expr $n + 1`
done
for host in `grep -v '^#' $input | grep -v '^[[:space:]]*$'`; do
cmd="ssh $useropt $host {$@}"
n=1
while [ $n -le $npasswords ]; do
password=`eval echo \\$password$n`
feedpass "$cmd" "$password"
[ $? -eq 0 ] && break
n=`expr $n + 1`
done
done