SG_SENDDIAG(8)
π sg_senddiag β the SEND DIAGNOSTIC bestie π
ok so welcome to SG_SENDDIAG(8), part of the SG3_UTILS fam π this is the manual page for the sg_senddiag utility, and bestie, it's lowkey the whole diagnostic vibe.
β¨ NAME β¨
sg_senddiagβ performs a SCSI SEND DIAGNOSTIC command π
πΈ SYNOPSIS πΈ
sg_senddiag [--doff] [--extdur] [--help] [--hex] [--list] [--maxlen=LEN]
[--page=PG] [--pf] [--raw=H,H...] [--raw=-] [--selftest=ST] [--test]
[--timeout=SECS] [--uoff] [--verbose] [--version] DEVICE
sg_senddiag [-doff] [-e] [-h] [-H] [-l] [-pf] [-raw=H,H...] [-raw=-]
[-s=ST] [-t] [-T=SECS] [-uoff] [-v] [-V] [-?] DEVICE
π¦ DESCRIPTION π¦
So, this utility sends a SCSI SEND DIAGNOSTIC command to the DEVICE. That's it, that's the whole personality. It can issue self-tests, find supported diagnostic pages, or send arbitrary diagnostic pages β pick your fighter β¨
When the --list option and a DEVICE are given, the utility sends a SCSI RECEIVE DIAGNOSTIC RESULTS command to fetch the response (i.e. the page numbers of supported diagnostic pages). Iconic behaviour.
When the --list option is given without a DEVICE, then a list of diagnostic page names and their numbers, known by this utility, are listed. no device needed, just vibes π«Ά
This utility supports two command line syntax-es. The preferred one is shown first in the synopsis and explained in this section. A later section on the old command line syntax outlines the second group of options. (Yes, two syntaxes. it's giving legacy support, and we respect it π)
π OPTIONS π
Arguments to long options are mandatory for short options as well. fr fr.
-d,--doffβ set the Device Offline (DevOffL) bit (default is clear). Only significant when--testoption is set for the default self-test. When set, other operations on any logical units controlled by the this device server (target) may be affected (delayed) while a default self-test is underway. so like, heads up π-e,--extdurβ outputs the expected extended self-test duration. The duration is given in seconds (and minutes in parentheses). This figure is obtained from mode page0xa(i.e. the control mode page). cute little number for you π-h,--helpβ print usage message then exit. the classic.-H,--hexβ outputs response from RECEIVE DIAGNOSTIC RESULTS in hex rather than decode it. Only the Supported Diagnostic Pages diagnostic page (i.e.page_code=0) is decoded; other pages (e.g. those used by SES) are output in hex. Now, the levels, bestie, listen:- If
--hexis used once, the hex output has a relative address at the start of each line. - If
--hexis used twice, then ASCII is shown to the right of each line of hex. - If
--hexis used three times or more, only the hex is output, in two character pairs (i.e. a byte) space separated and up to 16 bytes per line. This latter form, if placed in a file or piped through to another invocation, is suitable for the--raw=-option. pipeline queen π₯
- If
-l,--listβ when aDEVICEis also given, lists the names of all diagnostic pages supported by this device. The request is sent via a SEND DIAGNOSTIC command (with the "pF" bit set) and the response is fetched by a RECEIVE DIAGNOSTIC RESULTS command. When used in the absence of a--listargument then a list of diagnostic page names and their numbers, known by this utility, are listed. yes, it says--listargument, that's the original wording, we don't touch the wording π-m,--maxlen=LENβ whereLENis the value placed in the parameter list length field of a SEND DIAGNOSTIC command or in the allocation length field of a RECEIVE DIAGNOSTIC RESULTS command. This only occurs when the other options imply there will be data sent or received by the command. The default value is4096bytes.LENcannot exceed65535or0xffffin hexadecimal. know the limit, respect the limit β-O,--oldβ Switch to older style options. Please use as first option. (put it first, she's fussy π)-P,--page=PGβ wherePGis the RECEIVE DIAGNOSTIC RESULTS command page code field. If this option is given the PCV bit in that command is set. When this option is given then no SEND DIAGNOSTIC command is sent (unlike--list). IfPGis0then the response is decoded as if it is the SPC Supported Diagnostic pages diagnostic page. OtherPGvalues (i.e.1to255) have their responses output in hex. raw hex mode unlocked π¦-p,--pfβ set Page Format (PF) bit. By default it is clear (i.e.0) unless the list--listoption is given, in which case the Page Format bit is set (as required by SPC-3). the standard said so, so we do it β¨-r,--raw=H,H...β string of comma separated hex numbers each of which should resolve to a byte value (i.e.0toffinclusive). A (single) space separated string of hex bytes is also allowed but the list needs to be in quotes. This sequence forms a diagnostic page to be sent with the SCSI SEND DIAGNOSTIC command. Mostly likely the--pfoption should also be given. go off with your custom bytes π-r,--raw=-β reads sequence of bytes from stdin. The sequence may be comma, space, tab or linefeed (newline) separated. If a line contains"#"then the remaining characters on that line are ignored. Otherwise each non separator character should resolve to a byte value (i.e.0toffinclusive). This sequence forms a diagnostic page to be sent with the SCSI SEND DIAGNOSTIC command. Mostly likely the--pfoption should also be given. stdin girlies rise π-s,--selftest=STβ whereSTis the self-test code. The default value is0which is inactive. Some other values:
1 : background short self-test
2 : background extended self-test
4 : aborts a (background) self-test that is in progress
5 : foreground short self-test
6 : foreground extended self-test
This option is mutually exclusive with default self-test (i.e. can't have (ST > 0) and --test). pick a lane, babe π
-t,--testβ sets the _default_ Self Test (SelfTest) bit. By default this is clear (0). The--selftest=SToption should not be active together with this option. Both the--doffand/or--uoffoptions can be used with this option. team player energy π«Ά-T,--timeout=SECSβ whereSECSis a timeout value (in seconds) for foreground self-test operations. The default value is7200seconds (2 hours) and any values ofSECSless than the default are ignored. so like, you can't ask for less. she said no πΈ-u,--uoffβ set the Unit Offline (UnitOffL) bit (default is clear). Only significant when--testoption is set for the default self-test. When set, other operations on this logical unit may be affected (delayed) while a default self-test is underway. Some devices (e.g. Fujitsu disks) do more tests when this bit is set. Fujitsu said extra credit π-v,--verboseβ increase level of verbosity. Can be used multiple times. stack 'em π-V,--versionβ print out version string then exit. bye bestie π
π§ NOTES π§
All devices should support the default self-test. The 'short' self-test codes should complete in 2 minutes or less. The 'extended' self-test codes' maximum duration is vendor specific (e.g. a little over 10 minutes with the author's disks). The foreground self-test codes wait until they are completed while the background self-test codes return immediately. The results of both foreground and background self-test codes are placed in the 'self-test results' log page (see sg_logs(8)). The SCSI command timeout for this utility is set to 60 minutes to allow for slow foreground extended self-tests. she's patient, ok π°οΈ
If the DEVICE is a disk then no file systems residing on that disk should be mounted during a foreground self-test. The reason is that other SCSI commands may become queued behind the foreground self-test and timeout. like, seriously, unmount first, that's not a drill π
When the--raw=H,H...option is given then self-tests should not be selected. However the--pf(i.e. "page format") option should be given. The length of the diagnostic page to be sent is derived from the number of bytes given to the--raw=H,H...option. The diagnostic page code (number) should be the first byte of the sequence (i.e. as dictated by SPC-3 diagnostic page format). See the EXAMPLES section below. (examples are coming, hold on π)
Arbitrary diagnostic pages can be read (in hex) with the sg_ses(8) utility (not only those defined in SES-2). handy π
If the utility is used with no options (e.g. "sg_senddiag /dev/sg1") then a degenerate SCSI SEND DIAGNOSTIC command is sent with zero in all its fields apart from the opcode. Some devices report this as an error while others ignore it. It is not entirely clear from SPC-3 if it is invalid to send such a command. mystery behaviour, we simply report it π¦
In the 2.4 series of Linux kernels the DEVICE must be a SCSI generic (sg) device. In the 2.6 series block devices (e.g. SCSI disks and DVD drives) can also be specified. kernel history lesson, periodt β
To access SCSI enclosures see the sg_ses(8) utility. sg_ses uses the SCSI SEND DIAGNOSTIC and RECEIVE DIAGNOSTIC RESULTS commands as outlined in the SES-2 (draft) standard. different utility, same commands, love that for them π
π₯ EXIT STATUS π₯
The exit status of sg_senddiag is 0 when it is successful. Otherwise see the sg3_utils(8) man page. zero means slay, anything else means go read the other page π
π°οΈ OLDER COMMAND LINE OPTIONS π°οΈ
okay so this is the vintage corner, bestie. These options were literally the only ones available before sg3_utils version 1.23. Since then, this utility defaults to the newer command line options, and you can override that by using --old (or -O) as the first option. There's also another way to force these older options β peep the ENVIRONMENT VARIABLES section below. π
-doffβ sets the Device Offline (DevOffL) bit (default is clear). This only matters when the-toption is set for the default self-test. Equivalent to--doffin the main description.-eβ outputs the expected extended self-test duration. Equivalent to--extdurin the main description.-hβ outputs the response from RECEIVE DIAGNOSTIC RESULTS in hex instead of decoding it.-Hβ same vibes: outputs the response from RECEIVE DIAGNOSTIC RESULTS in hex instead of decoding it.-lβ when aDEVICEis also given, lists the names of all diagnostic pages supported by that device. The request is sent via a SEND DIAGNOSTIC command (with the"pf"bit set), and the response is fetched by a RECEIVE DIAGNOSTIC RESULTS command. When used with noDEVICEargument, it lists the diagnostic page names and their numbers that this utility knows about.-N,--newβ switches to the newer style options. slay.-pfβ sets the Page Format (PF) bit. By default it's clear (i.e.0) unless the-loption is given, in which case the Page Format bit is set (as required by SPC-3).-raw=H,H...β a string of comma-separated hex numbers, each of which should resolve to a byte value (i.e.0toffinclusive). This sequence forms a diagnostic page to be sent with the SCSI SEND DIAGNOSTIC command. You'll most likely want to give the-pfoption too.-raw=-β reads a sequence of bytes fromstdin. The sequence may be comma, space, tab or linefeed (newline) separated. If a line contains"#"then the remaining characters on that line are ignored. Otherwise each non-separator character should resolve to a byte value (i.e.0toffinclusive). This sequence forms a diagnostic page to be sent with the SCSI SEND DIAGNOSTIC command. You'll most likely want to give the-pfoption too.-s=STβ whereSTis the self-test code. The default value is0, which is inactive. A value of1selects a background short self-test;2selects a background extended self-test;5selects a foreground short self-test;6selects a foreground extended test. A value of4will abort a (background) self-test that is in progress. This option is mutually exclusive with the default self-test (i.e.-t).-tβ sets the default Self Test (SelfTest) bit. By default this is clear (0). The-s=SToption should not be active together with this option. Both the-doffand/or-uoffoptions can be used with this option.-T=SECSβ whereSECSis a timeout value (in seconds) for foreground self-test operations. See the--timeout=SECSoption above.-uoffβ sets the Unit Offline (UnitOffL) bit (default is clear). Equivalent to--uoffin the main description.-vβ increases the level of verbosity. Can be used multiple times.-Vβ prints out the version string, then exits.-?β outputs the usage message. Ignores all other parameters.
β¨ EXAMPLES β¨
The examples sub-directory in the sg3_utils packages contains two example scripts that turn on the CJTPAT (jitter pattern) on some SAS disks (one script for each phy). One possible invocation for phy 1 is:
sg_senddiag --pf --raw=- /dev/sg2 < sdiag_sas_p1_cjtpat.txt
There's also an example script that turns on the IDLE pattern. Once a test pattern has been started, it can be turned off by resetting the phy or with the STOP phy pattern function:
sg_senddiag --pf --raw=- /dev/sg2 < sdiag_sas_p1_stop.txt
π ENVIRONMENT VARIABLES π
Since sg3_utils version 1.23, the environment variable SG3_UTILS_OLD_OPTS can be given. When it's present, this utility will expect the older command line options. So basically, the presence of this environment variable is equivalent to using --old (or -O) as the first command line option. iconic behavior, honestly. π
π AUTHOR π
Written by Douglas Gilbert.
π REPORTING BUGS π
Report bugs to <dgilbert at interlog dot com>.
π COPYRIGHT π
Copyright Β© 2003-2018 Douglas Gilbert
This software is distributed under the GPL version 2. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
π¦ SEE ALSO π¦
sg_ses(8)sg_logs(8)smartmontools(see net)
This little masterpiece comes from sg3_utils-1.43, dated May 2018, and it's the SG_SENDDIAG(8) page. bye bestie, go send some diagnostics responsibly π«Άπ
π¦ where this page comes from
- arch rolling: sg3_utils 1.49-1 Β· GPL-2.0-or-later AND BSD-2-Clause
- nixpkgs unstable: sg3_utils 1.49
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms