iSCSIADM
Using iscsiadm to manage scsi logins to the storage
Script - Auto discover
Create a script as below
eg. vim iscsi_login_multiple
Fill the script with the following contents
#!/bin/bash
# Check if at least one target IP is provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <target_IP1> [target_IP2] ... [target_IPn]"
exit 1
fi
PORT="3260" # Default iSCSI port
# Loop through each target IP provided as an argument
for TARGET_IP in "$@"; do
echo "Processing $TARGET_IP..."
# Discover iSCSI targets on the current IP
echo "Discovering iSCSI targets on $TARGET_IP..."
TARGETS=$(iscsiadm -m discovery -t sendtargets -p $TARGET_IP | awk '{print $2}')
if [ -z "$TARGETS" ]; then
echo "No targets found on $TARGET_IP"
continue
fi
# Log in to each target and make the sessions persistent
for TARGET in $TARGETS; do
echo "Logging in to target $TARGET on $TARGET_IP..."
iscsiadm -m node -T $TARGET -p $TARGET_IP:$PORT --login
iscsiadm -m node -T $TARGET -p $TARGET_IP:$PORT --op update -n node.startup -v automatic
done
echo "Completed processing $TARGET_IP."
done
echo "All specified targets have been logged in and configured for automatic startup."
Make the script executable
eg. chmod +x iscsi_login_multiple
Run the scipt
You can now run the script and provide all possible iscsi ports on the target storage.
eg. iscsi_login_multiple 192.168.1.100 192.168.1.101 192.168.1.102
This script does not require iqns to establish connections