This is an old revision of the document!
Here's the code:
#!/bin/bash
#TO-DO: add argument checking, add argument for ssh host, add argument for ssh opts
# establish one ssh session per host which is killed automatically after disconnecting
# parameters- username, domain, etc.
if [ -z $BASH_ARGC ];
then echo "Usage: $0 host username domain start_port_number remote_host1 [ remote_host2 remote_host3 ... ]";
echo "Note: 'start_port_number' must be greater than 1024.";
exit 0;
fi
host=$1
username=$2
domain=$3
start_port=$4
#Get a password
read -s -p "Enter password: " pass
echo
echo "Establishing connections..."
echo
if [ -z $pass ];
then echo;echo;echo "You must enter a password";echo;exit 1;
fi
# Old...
#start_port=$1
#$(echo $1|cut -b1-$((${#1} - 1)))
#echo $start_port
#Fill arrays with values
j=0
for (( i=(( $# + $start_port - 5 ));i >= $start_port; i--));
do
hostlist[$j]="$(echo $i:${BASH_ARGV[$j]}:3389)"
myarray[$j]="${BASH_ARGV[$j]} $i"
myarray2[$j]="localhost:$i"
j=$(( $j+1 ));
done
for (( i=(( $# - 5 ));i >= 0; i--));
do
ssh -C -L ${hostlist[$i]} -N $host &
done
sleep 2
for (( i=(( $# - 5 ));i >= 0; i--));
do
rdesktop -a 16 -g 1300x720 -d $domain -u $username -p $pass -T "${myarray[$i]}" ${myarray2[$i]} &
done
for (( i=(( ${#hostlist[@]} - 1 )) ; i >= 0; i-- ))
do
tmpvar=$(ps ax | grep "${hostlist[$i]}" | grep -v grep | cut -b1-6);
SSHPID=$(echo $SSHPID $tmpvar);
done
echo
echo
read -p "Press Enter to terminate ssh connections..."
echo "Killing PID's: $SSHPID"
kill $SSHPID
exit 0;