ssh 649 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. DIR=$(dirname `readlink -f $0`)
  3. . $DIR/testing.conf
  4. SSHCONF="-F $DIR/ssh_config"
  5. if [ $# == 0 ]
  6. then
  7. echo "$0 <host>"
  8. exit 1
  9. fi
  10. host=$1
  11. echo "$host" | grep -q "^\([0-9]\+\.\|[0-9a-fA-F]\+:\).*"
  12. if [ $? -eq 0 ]
  13. then
  14. # assume we got an ip address
  15. ip=$host
  16. else
  17. pos='$1'
  18. echo "$host" | grep -q ".*1$"
  19. if [ $? -eq 0 ]
  20. then
  21. # {host}1, use second address
  22. pos='$2'
  23. host=`echo "$host" | sed -n -e "s/1$//p"`
  24. fi
  25. ip="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, "{ print ${pos} }" | awk '{ print $1 }'`"
  26. if [ -z $ip ]
  27. then
  28. echo "Host '$host' unknown"
  29. exit 1
  30. fi
  31. fi
  32. shift
  33. exec ssh $SSHCONF -q root@$ip $@