Advertisement
Guest User

Untitled

a guest
Feb 1st, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. foo()
  4. {
  5. while read line; do
  6. # debugging
  7. echo " read line:$line"
  8.  
  9. # look for the line describing the assigned system device
  10. ihas=`echo "$line" | grep 'Attached scsi disk' | awk '{print $4};'`
  11.  
  12. # a 'non-zero' variable for $ihas means it's captured the disk device
  13. # assign the value of $ihas to $ret
  14. if [ -n "$ihas" ] && [ -z "$ret" ]; then
  15. echo " +++ found:$ihas len:${#ihas}"
  16. ret="$ihas"
  17. fi
  18. done < <(iscsiadm -m session -P 3)
  19.  
  20. # return the assigned device
  21. echo "$ret"
  22. }
  23.  
  24. # call foo() and return the device
  25. bar=$(foo)
  26. echo "foo() returned value:$bar len:${#bar}"
  27.  
  28. foo() returned value: read line:iSCSI Transport Class version 2.0-870
  29. read line:version 2.0-873
  30. read line:Target: 2017-01.ihost:ib-ssd-luns
  31. read line:Current Portal: 172.22.24.5:3260,1
  32. read line:Persistent Portal: 172.22.24.5:3260,1
  33. read line:**********
  34. read line:Interface:
  35. read line:**********
  36. read line:Iface Name: default
  37. read line:Iface Transport: tcp
  38. read line:Iface Initiatorname: iqn.1993-08.org.debian:01:b2c8ba7d76e3
  39. read line:Iface IPaddress: 172.22.24.7
  40. read line:Iface HWaddress: <empty>
  41. read line:Iface Netdev: <empty>
  42. read line:SID: 148
  43. read line:iSCSI Connection State: LOGGED IN
  44. read line:iSCSI Session State: LOGGED_IN
  45. read line:Internal iscsid Session State: NO CHANGE
  46. read line:*********
  47. read line:Timeouts:
  48. read line:*********
  49. read line:Recovery Timeout: 120
  50. read line:Target Reset Timeout: 30
  51. read line:LUN Reset Timeout: 30
  52. read line:Abort Timeout: 15
  53. read line:*****
  54. read line:CHAP:
  55. read line:*****
  56. read line:username: <empty>
  57. read line:password: ********
  58. read line:username_in: <empty>
  59. read line:password_in: ********
  60. read line:************************
  61. read line:Negotiated iSCSI params:
  62. read line:************************
  63. read line:HeaderDigest: None
  64. read line:DataDigest: None
  65. read line:MaxRecvDataSegmentLength: 262144
  66. read line:MaxXmitDataSegmentLength: 8192
  67. read line:FirstBurstLength: 65536
  68. read line:MaxBurstLength: 262144
  69. read line:ImmediateData: Yes
  70. read line:InitialR2T: Yes
  71. read line:MaxOutstandingR2T: 1
  72. read line:************************
  73. read line:Attached SCSI devices:
  74. read line:************************
  75. read line:Host Number: 154 State: running
  76. read line:scsi154 Channel 00 Id 0 Lun: 0
  77. read line:scsi154 Channel 00 Id 0 Lun: 1
  78. read line:Attached scsi disk sdc State: running
  79. +++ found:sdc len:3
  80. sdc len:1771
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement