vm-start/ssh-local.sh

70 lines
1.6 KiB
Bash
Raw Normal View History

#/bin/bash
#
# little class about bash extension parametters.
#
# ${myvar#pattern} delete shortest occurence from the begining
# ${myvar##pattern} delete longuest occurence from begining
# ${myvar%pattern} delete shortest occurence from the end
# ${myvar%%pattern} delete longuest occurence from the end
#
# conclusion, use of # will delete the pattern at begining
# and % will delete the parameter at the end.
USER="root"
PORT=10022
VERSION="1.0"
HELP_MESSAGE="
ssh-local [OPTION] [OPTION=VALUE]
script which permit to launch ssh to connect to the vm on localhost without letting any traces on this computer.
-u <user>,--user=<user> Select the user, by default root
-p <port>,--port=<port> Select the port, by default 10022
-v, --version print the version and exit
-h, --help print this help and exit
"
# looking for double parametters.
for (( arg=1; arg<$#; arg++)); do
value="$((arg+1))"
if [ "${!arg}" == "-u" ]
then
USER=${!value}
elif [ "${!arg}" == "-p" ]
then
PORT=${!value}
fi
done
# looking for all parametter alone
for i in "$@"; do
if [ "${i%=*}" == "--user" ]
then
USER="${i#*=}"
elif [ "${i%=*}" == "--port" ]
then
PORT="${i#*=}"
elif [ "${i}" == "--version" ] || [ "${i}" == "-v" ]
then
echo "Prog ssh-local v.${VERSION}"
exit 0
elif [ "${i}" == "--help" ] || [ "${i}" == "-h" ]
then
echo "$HELP_MESSAGE"
exit 0
fi
done
echo user=${USER}
echo port=${PORT}
ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile=/dev/null" ${USER}@localhost -p ${PORT}