Advertisement
Morgan_iv

Untitled

Oct 2nd, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.88 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [[ $# = 0 ]]
  4. then
  5. echo "Use -a <name> to connect to server with name <name>"
  6. echo "Use -l command to get list of available servers with their names"
  7. echo "Use -h to get this help message again"
  8. exit 0
  9. fi
  10.  
  11. while getopts a:lh option
  12. do
  13. case "${option}"
  14. in
  15. a) ADR=${OPTARG}
  16. REQ=0
  17. ;;
  18. l) REQ=1;;
  19. h) echo "Use -a <name> to connect to server with name <name>"
  20. echo "Use -l command to get list of available servers with their names"
  21. echo "Use -h to get this help message again"
  22. exit 0
  23. ;;
  24. *) echo "Unavailable option, use $0 -h to get help";;
  25. esac
  26. done
  27.  
  28. declare -A NAMES
  29. NAMES[ivs]='root@123.123.123.123'
  30. NAMES[msu]='s02160069@prac.cs.msu.ru'
  31.  
  32. if [[ ${REQ} = 1 ]]
  33. then
  34.         echo "name  address"
  35.         for ind in "${!NAMES[@]}"
  36.         do
  37.                 echo "${ind}   ${NAMES[${ind}]}"
  38.         done
  39.         exit 0
  40. else
  41.         ssh ${NAMES[${ADR}]}
  42. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement