User Tools

Site Tools


unix:linux:iscsi_tricks_and_techniques

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
unix:linux:iscsi_tricks_and_techniques [2019/08/14 19:43] rodolicounix:linux:iscsi_tricks_and_techniques [2022/07/19 17:46] rodolico
Line 30: Line 30:
  
 <code perl addAlliSCSIS.pl> <code perl addAlliSCSIS.pl>
-#! /usr/bin/perl -w+#! /usr/bin/env perl
  
-my @servers = ( '10.5.136.1' ); +use strict; 
 +use warnings; 
 + 
 +# change following to be a list of 1 or more iSCSI targets to be queried 
 +my @servers = ( '10.10.10.10','10.10.10.9' ); 
 my %targets; my %targets;
  
  
 foreach my $server ( @servers ) { foreach my $server ( @servers ) {
 +   print "\n" . '-'x40 . "\nGetting targets on server $server\n" . '-'x40 . "\n";
    my @list = `iscsiadm -m discovery -t st -p $server`;    my @list = `iscsiadm -m discovery -t st -p $server`;
    chomp @list;    chomp @list;
Line 50: Line 55:
       # only add them if they are in this IP       # only add them if they are in this IP
       $targets{ $targetName } = $portal if $portal =~ m/^$server/;       $targets{ $targetName } = $portal if $portal =~ m/^$server/;
 +      print "$targetName\t$targets{ $targetName }\n";
    }    }
 } }
  
 +print "\n" . '-'x40 . "\nGetting active sessions\n". '-'x40 . "\n";
 # now, get active sessions so we can filter them # now, get active sessions so we can filter them
 my @activeSessions = `iscsiadm -m session`; my @activeSessions = `iscsiadm -m session`;
 chomp @activeSessions; chomp @activeSessions;
-foreach $session ( @activeSessions ) { +foreach my $session ( @activeSessions ) { 
-   $session =~ m/([0-9,:]+).* (.*)$/;+   $session =~ m/^.*[^0-9:.]([0-9,:.]+).*(iqn\S*)/;
    my ( $portal,$targetName ) = ( $1,$2 );    my ( $portal,$targetName ) = ( $1,$2 );
-   delete $targets{ $targetName if exists( $targets{$targetName} );+   print "$portal\t$targetName"; 
 +   if exists( $targets{$targetName} ) ) { 
 +      print "\tNOT updating\n"; 
 +      delete $targets{ $targetName }; 
 +   } else { 
 +      print "Needs to be added\n"; 
 +   }
 } }
  
Line 74: Line 87:
 } }
 # print `ls /dev/disk/by-path/`; # print `ls /dev/disk/by-path/`;
 +
 </code> </code>
  
Line 162: Line 176:
 # first, log out of the session # first, log out of the session
 iscsiadm -m node --target='name of target' --portal "ip:port" --logout iscsiadm -m node --target='name of target' --portal "ip:port" --logout
-# now, do a discovery and delete the entry from your local database +# now, do a remove it from the session 
-iscsiadm -m discovery --target='name of target' --portal "ip:port" -o delete+iscsiadm -m node --target='name of target' --portal "ip:port" -o delete
 </code> </code>
  
unix/linux/iscsi_tricks_and_techniques.txt · Last modified: 2022/12/17 14:05 by rodolico