ns-echoclient 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/sh
  2. ################################################################################
  3. ## ##
  4. ## Copyright (c) International Business Machines Corp., 2005 ##
  5. ## ##
  6. ## This program is free software; you can redistribute it and#or modify ##
  7. ## it under the terms of the GNU General Public License as published by ##
  8. ## the Free Software Foundation; either version 2 of the License, or ##
  9. ## (at your option) any later version. ##
  10. ## ##
  11. ## This program is distributed in the hope that it will be useful, but ##
  12. ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
  13. ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
  14. ## for more details. ##
  15. ## ##
  16. ## You should have received a copy of the GNU General Public License ##
  17. ## along with this program; if not, write to the Free Software ##
  18. ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ##
  19. ## ##
  20. ## ##
  21. ################################################################################
  22. #
  23. # File:
  24. # ns-echoclient
  25. #
  26. # Description:
  27. # Send various kind of echo request
  28. #
  29. # Author:
  30. # Mitsuru Chinen <mitch@jp.ibm.com>
  31. #
  32. # Options:
  33. # -S name or IP address of the server
  34. # -f protocol family
  35. # 4: IPv4
  36. # 6: IPv6
  37. # -s array of packet size
  38. # -t timeout [sec]
  39. # -h display this usage
  40. #
  41. # Outputs:
  42. # Process ID of the TCP traffic server
  43. #
  44. # Exit Value:
  45. # 0: Exit normally
  46. # >0: Exit abnormally
  47. #
  48. # History:
  49. # Oct 19 2005 - Created (Mitsuru Chinen)
  50. #
  51. #-----------------------------------------------------------------------
  52. #Uncomment line below for debug output.
  53. #trace_logic=${trace_logic:-"set -x"}
  54. $trace_logic
  55. #-----------------------------------------------------------------------
  56. #
  57. # Function: usage
  58. #
  59. # Description:
  60. # Print the usage of this script, then exit
  61. #
  62. # Argument
  63. # value: exit value
  64. #
  65. #-----------------------------------------------------------------------
  66. usage(){
  67. value=$1
  68. cat << EOD >&2
  69. ns-echoclient [OPTION]
  70. -S name or IP address of the server
  71. -f protocol family
  72. 4: IPv4
  73. 6: IPv6
  74. -s array of packet size
  75. -h display this usage
  76. EOD
  77. exit $value
  78. }
  79. #
  80. # Main
  81. #
  82. family=0
  83. while getopts 'S:f:s:h' opt ; do
  84. case $opt in
  85. 'S')
  86. server_name=$OPTARG
  87. ;;
  88. 'f')
  89. family=$OPTARG
  90. ;;
  91. 's')
  92. size_array="$OPTARG"
  93. ;;
  94. 'h')
  95. usage 0
  96. ;;
  97. *)
  98. echo "Unknown option" >&2
  99. usage 1
  100. ;;
  101. esac
  102. done
  103. # Check the server name
  104. if [ x$server_name = x ]; then
  105. echo "server name isn't specified."
  106. usage 1
  107. fi
  108. # Define the protocol family
  109. case $family in
  110. 4)
  111. ping_command="ping"
  112. ;;
  113. 6)
  114. ping_command="ping6"
  115. ;;
  116. *)
  117. echo "protocol family should be 4 or 6."
  118. usage 1
  119. ;;
  120. esac
  121. # Send the echo request
  122. if [ x"$size_array" = x ]; then
  123. $ping_command $server_name >/dev/null 2>&1 &
  124. else
  125. for size in $size_array ; do
  126. $ping_command -s $size $server_name >/dev/null 2>&1 &
  127. done
  128. fi
  129. exit 0