Created
February 1, 2017 00:34
-
-
Save bithive/e4548104676ccf6d137ae2ed8c6f88a1 to your computer and use it in GitHub Desktop.
Shell script to log in to multiple iSCSI targets, e.g. on an AWS Storage Gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Adapted for Debian from | |
# http://backdrift.org/how-to-connect-to-multiple-iscsi-targets-requiring-different-usernames-and-passwords | |
# Set $InitiatorName | |
. /etc/iscsi/initiatorname.iscsi | |
# Storage Gateway IP | |
PORTAL=172.31.2.56 | |
USERNAME[0]="iqn.1997-05.com.amazon:vdev-a" | |
PASSWORD1[0]=abcd123 | |
PASSWORD2[0]=efgh456 | |
USERNAME[1]="iqn.1997-05.com.amazon:vdev-b" | |
PASSWORD1[1]=ijkl789 | |
PASSWORD2[1]=mnop012 | |
USERNAME[2]="iqn.1997-05.com.amazon:vdev-c" | |
PASSWORD1[2]=qrst345 | |
PASSWORD2[2]=uvwx678 | |
# Perform discovery (note -o new argument, this is important) | |
TARGETS=(`iscsiadm -m discovery -t st -p ${PORTAL} -o new --discover | sort | awk '{print $2}'`) | |
i=0 | |
while [ $i -lt ${#TARGETS[@]} ]; do | |
# Set username/password individually for each target, and login | |
iscsiadm -m node --targetname ${TARGETS[$i]} -p ${PORTAL} -o update -n node.session.auth.username -v ${InitiatorName} | |
iscsiadm -m node --targetname ${TARGETS[$i]} -p ${PORTAL} -o update -n node.session.auth.password -v ${PASSWORD1[$i]} | |
iscsiadm -m node --targetname ${TARGETS[$i]} -p ${PORTAL} -o update -n node.session.auth.username_in -v ${USERNAME[$i]} | |
iscsiadm -m node --targetname ${TARGETS[$i]} -p ${PORTAL} -o update -n node.session.auth.password_in -v ${PASSWORD2[$i]} | |
iscsiadm -m node --targetname ${TARGETS[$i]} -p ${PORTAL} --login | |
# Log out of target | |
iscsiadm -m node --targetname ${TARGETS[$i]} --logout | |
i=$((i+1)) | |
done | |
# Log in to all nodes now | |
echo Logging in to all nodes | |
iscsiadm -m node --login |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment