Advertisement
xpinex

iscsi session -> device (disk)

Sep 12th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.30 KB | None | 0 0
  1. #!/bin/bash
  2. # Save the original IFS (Internal Field Seperator)
  3. OLDIFS=$IFS
  4. # Set the IFS to newline
  5. IFS=$'\n'
  6. # Go through the output of the iscsiadm command
  7. for LINE in $(/sbin/iscsiadm -m session -P3); do
  8.         case "$LINE" in
  9.         # If line contains Target:
  10.                 *Target:*)
  11.             # Save the target name in a variable
  12.                         TARGET=$(echo $LINE | awk '{print $2}')
  13.                         ;;
  14.         # If line contains Current Portal:
  15.                 *"Current Portal:"*)
  16.             # Save the IP, port and session information in a variable
  17.                         PORTAL=$(echo $LINE | awk '{print $3}' | tr ":" "\n")
  18.             # Remove port and session information from the variable
  19.                         PORTAL=(${PORTAL//:3260,1/ })
  20.                         ;;
  21.         # If line contains Attached scsi disk
  22.                 *"Attached scsi disk"*)
  23.             # Save the device name in a variable with /dev/ in front
  24.             # to give the full path to the device
  25.                         DEV="/dev/"$(echo $LINE | awk ' {print $4}')
  26.             # Print the found information
  27.                         echo "Target = $TARGET"
  28.                         echo "Portal = $PORTAL"
  29.                         echo "Device = $DEV"
  30.                         echo ""
  31.                         ;;
  32.         esac
  33. done
  34. # Restore the IFS
  35. IFS=$OLDIFS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement