#/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. default_user="root" default_hostname="localhost" default_ssh_port="22" default_rsp_port="3389" default_vnc_port="5900" Version="2.0.0" Help_message=" $(basename $0) PROTOCOL [OPTION] [OPTION=VALUE] script which permit to launch a remote connection protocol. PROTOCOL available ssh A command line protocol which can be used to connect with tcp rsp The windows remote server protocol PROTOCOL #TODO vnc Virtual Networking Computing, permit to have access to a graphical user interface. OPTION available -v, --version print the version and exit -h, --help print this help and exit -u ,--user= Select the user, by default root -p ,--port= Select the port, by default 10022 -H , --hostname= Select the host to connect #TODO " start_ssh() { if [ "${port}" == "" ] then port="${default_ssh_port}" fi echo "start ssh" } start_rsp() { if [ "${port}" == "" ] then port="${default_rsp_port}" fi echo "start rsp" } case "$1" in "ssh") protocol="ssh" ;; "rsp") protocol="rsp" ;; *) echo "protocol $1 uknown" >&2 exit 1 esac # looking for double parametters. for (( arg=2; arg<$#; arg++)); do value="$((arg+1))" if [ "${!arg}" == "-u" ] then user="${!value}" elif [ "${!arg}" == "-p" ] then port="${!value}" elif [ "${!arg}" == "-H" ] then hostname="${!arg}" 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#*=}" == "--hostname" ] then hostname="${i#*=}" elif [ "${i}" == "--version" ] || [ "${i}" == "-v" ] then echo "$(basename $0) v.${Version}" exit 0 elif [ "${i}" == "--help" ] || [ "${i}" == "-h" ] then echo "$Help_message" exit 0 fi done if [ "${user}" == "" ] then user="${default_user}" fi if [ "${hostname}" == "" ] then hostname="${default_hostname}" fi case "${protocol}" in "ssh") start_ssh ;; "rsp") start_rsp ;; *) echo "CRITICAL protocol ${protocol} uknown" >&2 exit 1 ;; esac echo try to connect with user=${user} and port=${port} echo port=${port} ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile=/dev/null" -p ${port} ${user}@localhost # add possibility for vnc and rsp # rsp command to connect: xfreerdp /v:hostname /u:user /dynamic-resolution