Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Save the original IFS (Internal Field Seperator)
- OLDIFS=$IFS
- # Set the IFS to newline
- IFS=$'\n'
- # Go through the output of the iscsiadm command
- for LINE in $(/sbin/iscsiadm -m session -P3); do
- case "$LINE" in
- # If line contains Target:
- *Target:*)
- # Save the target name in a variable
- TARGET=$(echo $LINE | awk '{print $2}')
- ;;
- # If line contains Current Portal:
- *"Current Portal:"*)
- # Save the IP, port and session information in a variable
- PORTAL=$(echo $LINE | awk '{print $3}' | tr ":" "\n")
- # Remove port and session information from the variable
- PORTAL=(${PORTAL//:3260,1/ })
- ;;
- # If line contains Attached scsi disk
- *"Attached scsi disk"*)
- # Save the device name in a variable with /dev/ in front
- # to give the full path to the device
- DEV="/dev/"$(echo $LINE | awk ' {print $4}')
- # Print the found information
- echo "Target = $TARGET"
- echo "Portal = $PORTAL"
- echo "Device = $DEV"
- echo ""
- ;;
- esac
- done
- # Restore the IFS
- IFS=$OLDIFS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement