home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / sg3-utils / examples / sg_persist_tst.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2007-03-14  |  2.1 KB  |  85 lines

  1. #!/bin/sh
  2. # This script is meant as an example of using the sg_persist utility
  3. # in the sg3_utils package. This script works as expected on the
  4. # author's Fujitsu MAM3184 and a Seagate ST373455 disk.
  5. #
  6. #  Version 1.5 20070314
  7.  
  8. # N.B. make sure the device name is correct for your environment.
  9.  
  10. if [ ! -n "$1" ];then
  11.         echo "Usage: `basename $0` <device_name>"
  12.         echo
  13.         echo "Tests various SCSI Persistent Reserve (in + out) commands."
  14.         echo "Should be harmless (unless key 0x123abc is already in use)."
  15.         exit 1
  16. fi
  17.  
  18. echo ">>> try to report capabilities:"
  19. sg_persist -c $1
  20. res=$?
  21. case "$res" in
  22.     0) ;;
  23.     1) echo "  syntax error" ;;
  24.     2) echo "  not ready" ;;
  25.     3) echo "  medium error" ;;
  26.     5) echo "  illegal request, report capabilities not supported?" ;;
  27.     6) echo "  unit attention" ;;
  28.     9) echo "  illegal request, Persistent Reserve (In) not supported" ;;
  29.     11) echo "  aborted command" ;;
  30.     15) echo "  file error with $1 " ;;
  31.     20) echo "  no sense" ;;
  32.     21) echo "  recovered error" ;;
  33.     33) echo "  timeout" ;;
  34.     97) echo "  response fails sanity" ;;
  35.     98) echo "  other SCSI error" ;;
  36.     99) echo "  other error" ;;
  37.     *) echo "  unknown exit status for sg_persist: $res" ;;
  38. esac
  39. echo ""
  40. sleep 1
  41.  
  42. echo ">>> check if any keys are registered:"
  43. sg_persist -k $1
  44. sleep 1
  45.  
  46. echo
  47. echo ">>> register a key:"
  48. sg_persist -n --out --register --param-sark=123abc $1
  49. sleep 1
  50.  
  51. echo
  52. echo ">>> now key 123abc should be registered:"
  53. sg_persist -n -k $1
  54. sleep 1
  55.  
  56. echo
  57. echo ">>> reserve the device (based on key 123abc):"
  58. sg_persist -n --out --reserve --param-rk=123abc --prout-type=1 $1
  59. sleep 1
  60.  
  61. echo
  62. echo ">>> check if the device is reserved (it should be now):"
  63. sg_persist -n --read-reservation $1
  64. sleep 1
  65.  
  66. echo
  67. echo ">>> now release reservation:"
  68. sg_persist -n --out --release --param-rk=123abc --prout-type=1 $1
  69. sleep 1
  70.  
  71. echo
  72. echo ">>> check if the device is reserved (it should _not_ be now):"
  73. sg_persist -n --read-reservation $1
  74. sleep 1
  75.  
  76. echo
  77. echo ">>> unregister key 123abc:"
  78. sg_persist -n --out --register --param-rk=123abc $1
  79. sleep 1
  80.  
  81. echo
  82. echo ">>> now key 123abc should not be registered:"
  83. sg_persist -n -k $1
  84. sleep 1
  85.