/usr/bin/rescan-scsi-bus.sh: line 245: test: -le: unary operator expected

Bug #1913729 reported by ser0ser
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
sg3-utils (Ubuntu)
Fix Released
Undecided
Unassigned
Bionic
Triaged
Low
Unassigned

Bug Description

When I run `/usr/bin/rescan-scsi-bus.sh -i` I get `unary operator expected` errors.

Like this:

Scanning SCSI subsystem for new devices
Scanning host 0 for all SCSI target IDs, all LUNs
 Scanning for device 0 0 0 0 ...
OLD: Host: scsi0 Channel: 00 Id: 00 Lun: 00
      Vendor: IBM Model: ULT3580-TD5 Rev: B6W0
      Type: Sequential-Access ANSI SCSI revision: 06
/usr/bin/rescan-scsi-bus.sh: line 245: test: -le: unary operator expected
/usr/bin/rescan-scsi-bus.sh: line 257: test: !=: unary operator expected
 Scanning for device 0 0 0 1 ...
OLD: Host: scsi0 Channel: 00 Id: 00 Lun: 01
      Vendor: IBM Model: 3573-TL Rev: A.40
      Type: Medium-Changer ANSI SCSI revision: 05
/usr/bin/rescan-scsi-bus.sh: line 245: test: -le: unary operator expected
/usr/bin/rescan-scsi-bus.sh: line 257: test: !=: unary operator expected
 Scanning for device 0 0 1 0 ...
OLD: Host: scsi0 Channel: 00 Id: 01 Lun: 00
      Vendor: IBM Model: 1746 FAStT Rev: 1070
      Type: Direct-Access ANSI SCSI revision: 05
/usr/bin/rescan-scsi-bus.sh: line 245: test: -le: unary operator expected
/usr/bin/rescan-scsi-bus.sh: line 257: test: !=: unary operator expected
...

ProblemType: Bug
DistroRelease: Ubuntu 18.04
Package: sg3-utils 1.42-2ubuntu1.18.04.2
ProcVersionSignature: Ubuntu 4.15.0-46.49-generic 4.15.18
Uname: Linux 4.15.0-46-generic x86_64
ApportVersion: 2.20.9-0ubuntu7.21
Architecture: amd64
Date: Fri Jan 29 12:25:43 2021
Dependencies:
 gcc-8-base 8.4.0-1ubuntu1~18.04
 libc6 2.27-3ubuntu1
 libgcc1 1:8.4.0-1ubuntu1~18.04
 libsgutils2-2 1.42-2ubuntu1.18.04.2
InstallationDate: Installed on 2012-07-19 (3116 days ago)
InstallationMedia: Ubuntu-Server 12.04 LTS "Precise Pangolin" - Release amd64 (20120424.1)
SourcePackage: sg3-utils
UpgradeStatus: Upgraded to bionic on 2018-11-05 (816 days ago)

Revision history for this message
ser0ser (ser-man) wrote :
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Bionic:

$ sudo /usr/bin/rescan-scsi-bus.sh -i
Scanning SCSI subsystem for new devices
Scanning host 0 for SCSI target IDs 0 1 2 3 4 5 6 7, all LUNs
Scanning host 1 for SCSI target IDs 0 1 2 3 4 5 6 7, all LUNs
Scanning host 2 for SCSI target IDs 0 1 2 3 4 5 6 7, all LUNs
Scanning host 3 for SCSI target IDs 0 1 2 3 4 5 6 7, all LUNs
Scanning host 4 for SCSI target IDs 0 1 2 3 4 5 6 7, all LUNs
Scanning host 5 for SCSI target IDs 0 1 2 3 4 5 6 7, all LUNs
0 new or changed device(s) found.
0 remapped or resized device(s) found.
0 device(s) removed.

Hirsute:
$ sudo /usr/bin/rescan-scsi-bus.sh -i
Scanning SCSI subsystem for new devices
Scanning host 0 for SCSI target IDs 0
1
2
3
4
5
6
7, all LUNs
Scanning host 1 for SCSI target IDs 0
1
2
3
4
5
6
7, all LUNs
Scanning host 2 for SCSI target IDs 0
1
2
3
4
5
6
7, all LUNs
Scanning host 3 for SCSI target IDs 0
1
2
3
4
5
6
7, all LUNs
Scanning host 4 for SCSI target IDs 0
1
2
3
4
5
6
7, all LUNs
Scanning host 5 for SCSI target IDs 0
1
2
3
4
5
6
7, all LUNs
0 new or changed device(s) found.
0 remapped or resized device(s) found.
0 device(s) removed.

So it isn't failing all the time.
I assume your environment is different in a way that some variable becomes "" and then the check fails.

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

245
  while test $RC = 2 -o $RC = 6 && test $ctr -le 30; do
257
  if test $ctr != 0; then white_out; fi

So the bad variable is "$ctr"

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

It is indeed a use before assign.

It isn't a problem if this while loop exits a check before the counter, but if not then the error will trigger.

This is the fix
https://github.com/hreinecke/sg3_utils/commit/b5dadcb663fd9aeacd8f6145bfd6d50df12c0163

Which is in 1.44

And thereby in Focal and later

Changed in sg3-utils (Ubuntu):
status: New → Fix Released
Changed in sg3-utils (Ubuntu Bionic):
status: New → Triaged
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Since all systems I've used didn't trigger it I wondered how common this case is.

Could you run it like:
  sudo bash -x /usr/bin/rescan-scsi-bus.sh -i

That should show you which devices are the ones triggering it for you.
Before the error there is a call to
    sg_turs /dev/$SGDEV >/dev/null 2>&1

That should have some odd RC codes that lead to the issue.

I was fetching a system with actual LUNs and then executed the new and old version.

New
...
+ SGDEV=sg19
+ test -z sg19
+ sg_turs /dev/sg19
+ RC=0
+ test 0 = 2 -o 0 = 6
+ test 0 '!=' 0
+ test 0 = 1
+ RC=0
++ sg_inq --len=36 /dev/sg19
...

New:
 Scanning for device 1 0 1 1076117540 ...
OLD: Host: scsi1 Channel: 00 Id: 01 Lun: 1076117540
      Vendor: IBM Model: 2107900 Rev: 2700
      Type: Direct-Access ANSI SCSI revision: 05
0 new or changed device(s) found.
0 remapped or resized device(s) found.
0 device(s) removed.

old:
...
      Type: Direct-Access ANSI SCSI revision: 05
./rescan-scsi-bus.sh: line 257: test: !=: unary operator expected
 Scanning for device 1 0 1 1076117540 ...
OLD: Host: scsi1 Channel: 00 Id: 01 Lun: 1076117540
      Vendor: IBM Model: 2107900 Rev: 2700
      Type: Direct-Access ANSI SCSI revision: 05
./rescan-scsi-bus.sh: line 257: test: !=: unary operator expected
0 new or changed device(s) found.
0 remapped or resized device(s) found.
0 device(s) removed.

So, yes it throws some errors in between the output. But it is already fixed in later versions (no todo there) and isn't a functional issue.

IMHO thereby it is of low priority - which does not stop anyone from preparing and providing an upload, just that it likely will wait way back in the queue.

Changed in sg3-utils (Ubuntu Bionic):
importance: Undecided → Low
Revision history for this message
ser0ser (ser-man) wrote :

It's `/dev/sg20` for me:

+ SGDEV=sg20
+ test -z sg20
+ sg_turs /dev/sg20
+ RC=5
+ test 5 = 2 -o 5 = 6
+ test '!=' 0
/usr/bin/rescan-scsi-bus.sh: line 257: test: !=: unary operator expected

And this sg20 points to 0:0:2:7 HCTL. I have no idea what it is. It shouldn't exist.
This server has 2 years of uptime. A lot could happen in that time :)

Good to know it isn't a functional problem. Thank you for investigation.

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Thanks ser0ser for the feedback!
That confirms that you are in "no other" situation than what I've found.

Revision history for this message
Lucas Kanashiro (lucaskanashiro) wrote :

Is anyone interested in preparing an upload to fix this issue? It is still in our long queue and it should not be tackled soon.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.