#!/bin/bash BASE="/localhomes/rabin/work/wireless/testbed/tools/tiernet/connect/" NUMARGS=$# if [[ $0 = *sshtier ]]; then TYPE=ssh TARGET=$1 shift OTHERARGS="$*" elif [[ $0 = *scptier ]]; then TYPE=scp TARGET=${!NUMARGS} #OTHERARGS="$@" let index=1 for ((;$index < $NUMARGS;)); do OTHERARGS="$OTHERARGS ${!index}" let index=$index+1 done fi if [ -f $BASE/testbed_connect.sh ]; then . $BASE/testbed_connect.sh else echo "error: need testbed_connect.sh at $BASE" exit 1 fi ########################################################################### #SSH ssh_login() { target=$1 shift otherargs=$* #get destination path too parts=(${target/:/ }) target=${parts[0]}; if [ "${#parts[*]}" == "2" ]; then path=${parts[1]}; fi #break username and host into parts parts=(${target/@/ }) if [ "${#parts[*]}" == "2" ]; then target=${parts[1]}; fi get_connect_params $target if [ "${#parts[*]}" == "2" ]; then CONNECT_USER=${parts[0]}; fi echo "connecting to $target: $CONNECT_USER@$CONNECT_IP port $CONNECT_PORT" if [ "$TYPE" == "ssh" ]; then if [ "$otherargs" ]; then echo "executing $otherargs"; fi ssh $CONNECT_USER@$CONNECT_IP -p $CONNECT_PORT $otherargs elif [ "$TYPE" == "scp" ]; then if [ "$otherargs" ]; then echo "copying $otherargs to $path"; fi scp -P $CONNECT_PORT $otherargs $CONNECT_USER@$CONNECT_IP:$path fi } ############################################################################## if [ "$NUMARGS" -lt "1" ]; then echo -e "usage: sshtier [user@]HOST [otherargs]" echo -e "HOST can be among: $FULL_LIST" exit 1 fi ############################################################################## ############################################################################## ssh_login $TARGET $OTHERARGS exit #/etc/hosts