{
    "mode": "man",
    "parameter": "sg_senddiag",
    "section": "8",
    "url": "https://www.chedong.com/phpMan.php/man/sg_senddiag/8/json",
    "generated": "2026-10-05T01:25:11Z",
    "synopsis": "sgsenddiag  [--doff]  [--extdur] [--help] [--hex] [--list] [--maxlen=LEN] [--page=PG] [--pf]\n[--raw=H,H...]  [--raw=-]  [--selftest=ST]  [--test]  [--timeout=SECS]  [--uoff]  [--verbose]\n[--version] DEVICE\nsgsenddiag  [-doff]  [-e] [-h] [-H] [-l] [-pf] [-raw=H,H...] [-raw=-] [-s=ST] [-t] [-T=SECS]\n[-uoff] [-v] [-V] [-?]  DEVICE",
    "sections": {
        "NAME": {
            "content": "sgsenddiag - performs a SCSI SEND DIAGNOSTIC command\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "sgsenddiag  [--doff]  [--extdur] [--help] [--hex] [--list] [--maxlen=LEN] [--page=PG] [--pf]\n[--raw=H,H...]  [--raw=-]  [--selftest=ST]  [--test]  [--timeout=SECS]  [--uoff]  [--verbose]\n[--version] DEVICE\n\nsgsenddiag  [-doff]  [-e] [-h] [-H] [-l] [-pf] [-raw=H,H...] [-raw=-] [-s=ST] [-t] [-T=SECS]\n[-uoff] [-v] [-V] [-?]  DEVICE\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This utility sends a SCSI SEND DIAGNOSTIC command to the DEVICE.  It  can  issue  self-tests,\nfind supported diagnostic pages or send arbitrary diagnostic pages.\n\nWhen  the --list option and a DEVICE are given then the utility sends a SCSI RECEIVE DIAGNOS‐\nTIC RESULTS command to fetch the response (i.e.  the page  numbers  of  supported  diagnostic\npages).\n\nWhen  the  --list  option  is given without a DEVICE then a list of diagnostic page names and\ntheir numbers, known by this utility, are listed.\n\nThis utility supports two command line syntax-es, the preferred one is  shown  first  in  the\nsynopsis  and  explained in this section. A later section on the old command line syntax out‐\nlines the second group of options.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "Arguments to long options are mandatory for short options as well.\n",
            "subsections": [
                {
                    "name": "-d --doff",
                    "content": "set the Device Offline (DevOffL) bit (default is clear). Only significant when  --test\noption  is  set  for  the  default self-test. When set other operations on any logical\nunits controlled by the this device server (target) may be affected (delayed) while  a\ndefault self-test is underway.\n",
                    "flag": "-d",
                    "long": "--doff"
                },
                {
                    "name": "-e --extdur",
                    "content": "outputs  the  expected  extended  self-test duration. The duration is given in seconds\n(and minutes in parentheses). This figure is obtained from mode  page  0xa  (i.e.  the\ncontrol mode page).\n",
                    "flag": "-e",
                    "long": "--extdur"
                },
                {
                    "name": "-h --help",
                    "content": "print usage message then exit.\n",
                    "flag": "-h",
                    "long": "--help"
                },
                {
                    "name": "-H --hex",
                    "content": "outputs  response  from RECEIVE DIAGNOSTIC RESULTS in hex rather than decode it.  Only\nthe Supported Diagnostic Pages diagnostic page (i.e. pagecode=0)  is  decoded;  other\npages (e.g. those used by SES) are output in hex.\nIf  --hex  is  used  once,  the hex output has a relative address at the start of each\nline. If --hex is used twice, then ASCII is shown to the right of each line of hex. If\n--hex is used three time or more, only the hex is output, in two character pairs (i.e.\na byte) space separated and up to 16 bytes per line. This latter form, if placed in  a\nfile or piped through to another invocation, is suitable for the --raw=- option.\n",
                    "flag": "-H",
                    "long": "--hex"
                },
                {
                    "name": "-l --list",
                    "content": "when  a DEVICE is also given lists the names of all diagnostic pages supported by this\ndevice. The request is sent via a SEND DIAGNOSTIC command (with the \"pF\" bit set)  and\nthe  response is fetched by a RECEIVE DIAGNOSTIC RESULTS command. When used in the ab‐\nsence of a --list argument then a list of diagnostic page  names  and  their  numbers,\nknown by this utility, are listed.\n",
                    "flag": "-l",
                    "long": "--list"
                },
                {
                    "name": "-m --maxlen",
                    "content": "where  LEN is the value placed in the parameter list length field of a SEND DIAGNOSTIC\ncommand or in the allocation length field of a  RECEIVE  DIAGNOSTIC  RESULTS  command.\nThis  only  occurs when the other options imply there will be data sent or received by\nthe command. The default value is 4096 bytes. LEN cannot exceed  65535  or  0xffff  in\nhexadecimal.\n",
                    "flag": "-m",
                    "long": "--maxlen"
                },
                {
                    "name": "-O --old",
                    "content": "Switch to older style options. Please use as first option.\n",
                    "flag": "-O",
                    "long": "--old"
                },
                {
                    "name": "-P --page",
                    "content": "where PG is the RECEIVE DIAGNOSTIC RESULTS command page code field.  If this option is\ngiven the PCV bit in that command is set. When this option is given then no SEND DIAG‐\nNOSTIC command is sent (unlike --list).  If PG is 0 then the response is decoded as if\nit  is  the SPC Supported Diagnostic pages diagnostic page. Other PG values (i.e. 1 to\n255) have their responses output in hex.\n",
                    "flag": "-P",
                    "long": "--page"
                },
                {
                    "name": "-p --pf",
                    "content": "set Page Format (PF) bit. By default it is clear (i.e. 0) unless the list  --list  op‐\ntion is given in which case the Page Format bit is set (as required by SPC-3).\n",
                    "flag": "-p",
                    "long": "--pf"
                },
                {
                    "name": "-r --raw",
                    "content": "string  of  comma  separated  hex numbers each of which should resolve to a byte value\n(i.e. 0 to ff inclusive). A (single) space separated string of hex bytes is  also  al‐\nlowed  but the list needs to be in quotes. This sequence forms a diagnostic page to be\nsent with the SCSI SEND DIAGNOSTIC command. Mostly likely the --pf option should  also\nbe given.\n",
                    "flag": "-r",
                    "long": "--raw"
                },
                {
                    "name": "-r --raw=-",
                    "content": "reads  sequence of bytes from stdin. The sequence may be comma, space, tab or linefeed\n(newline) separated. If a line contains \"#\" then the remaining characters on that line\nare ignored. Otherwise each non separator character should resolve  to  a  byte  value\n(i.e.  0  to  ff inclusive). This sequence forms a diagnostic page to be sent with the\nSCSI SEND DIAGNOSTIC command. Mostly likely the --pf option should also be given.\n",
                    "flag": "-r",
                    "long": "--raw",
                    "arg": "-"
                },
                {
                    "name": "-s --selftest",
                    "content": "where ST is the self-test code. The default value is 0 which is inactive.  Some  other\nvalues:\n1 : background short self-test\n2 : background extended self-test\n4 : aborts a (background) self-test that is in progress\n5 : foreground short self-test\n6 : foreground extended self-test\nThis  option  is  mutually exclusive with default self-test (i.e.  can't have (ST > 0)\nand --test).\n",
                    "flag": "-s",
                    "long": "--selftest"
                },
                {
                    "name": "-t --test",
                    "content": "sets the default Self Test (SelfTest) bit.  By  default  this  is  clear  (0).   The\n--selftest=ST  option  should not be active together with this option. Both the --doff\nand/or --uoff options can be used with this option.\n",
                    "flag": "-t",
                    "long": "--test"
                },
                {
                    "name": "-T --timeout",
                    "content": "where SECS is a timeout value (in seconds) for foreground  self-test  operations.  The\ndefault  value  is 7200 seconds (2 hours) and any values of SECS less than the default\nare ignored.\n",
                    "flag": "-T",
                    "long": "--timeout"
                },
                {
                    "name": "-u --uoff",
                    "content": "set the Unit Offline (UnitOffL) bit (default is clear). Only significant  when  --test\noption  is  set  for  the default self-test. When set other operations on this logical\nunit may be affected (delayed) while a default self-test  is  underway.  Some  devices\n(e.g. Fujitsu disks) do more tests when this bit is set.\n",
                    "flag": "-u",
                    "long": "--uoff"
                },
                {
                    "name": "-v --verbose",
                    "content": "increase level of verbosity. Can be used multiple times.\n",
                    "flag": "-v",
                    "long": "--verbose"
                },
                {
                    "name": "-V --version",
                    "content": "print out version string then exit.\n",
                    "flag": "-V",
                    "long": "--version"
                }
            ]
        },
        "NOTES": {
            "content": "All devices should support the default self-test. The 'short' self-test codes should complete\nin  2  minutes  or  less. The 'extended' self-test codes' maximum duration is vendor specific\n(e.g. a little over 10 minutes with the author's disks). The foreground self-test codes  wait\nuntil they are completed while the background self-test codes return immediately. The results\nof  both  foreground and background self-test codes are placed in the 'self-test results' log\npage (see sglogs(8)). The SCSI command timeout for this utility is set to 60 minutes to  al‐\nlow for slow foreground extended self-tests.\n\nIf the DEVICE is a disk then no file systems residing on that disk should be mounted during a\nforeground  self-test.  The  reason  is that other SCSI commands may become queued behind the\nforeground self-test and timeout.\n\nWhen the --raw=H,H... option is given then self-tests should not  be  selected.  However  the\n--pf  (i.e.  \"page  format\")  option should be given. The length of the diagnostic page to be\nsent is derived from the number of bytes given to the  --raw=H,H...  option.  The  diagnostic\npage  code (number) should be the first byte of the sequence (i.e. as dictated by SPC-3 diag‐\nnostic page format). See the EXAMPLES section below.\n\nArbitrary diagnostic pages can be read (in hex) with the sgses(8) utility  (not  only  those\ndefined in SES-2).\n\nIf  the  utility is used with no options (e.g. \"sgsenddiag /dev/sg1\") Then a degenerate SCSI\nSEND DIAGNOSTIC command is sent with zero in all its fields apart from the opcode.  Some  de‐\nvices  report this as an error while others ignore it. It is not entirely clear from SPC-3 if\nit is invalid to send such a command.\n\nIn the 2.4 series of Linux kernels the DEVICE must be a SCSI generic (sg) device. In the  2.6\nseries block devices (e.g. SCSI disks and DVD drives) can also be specified.\n\nTo access SCSI enclosures see the sgses(8) utility. sgses uses the SCSI SEND DIAGNOSTIC and\nRECEIVE DIAGNOSTIC RESULTS commands as outlined in the SES-2 (draft) standard.\n",
            "subsections": []
        },
        "EXIT STATUS": {
            "content": "The exit status of sgsenddiag is 0 when it is successful. Otherwise see the sg3utils(8) man\npage.\n",
            "subsections": []
        },
        "OLDER COMMAND LINE OPTIONS": {
            "content": "The  options  in  this section were the only ones available prior to sg3utils version 1.23 .\nSince then this utility defaults to the newer command line options which can be overridden by\nusing --old (or -O) as the first option. See the ENVIRONMENT VARIABLES  section  for  another\nway to force the use of these older command line options.\n",
            "subsections": [
                {
                    "name": "-doff",
                    "content": "tion is set for the default self-test. Equivalent to --doff in the main description.\n"
                },
                {
                    "name": "-e",
                    "content": "description.\n",
                    "flag": "-e"
                },
                {
                    "name": "-h",
                    "content": "",
                    "flag": "-h"
                },
                {
                    "name": "-H",
                    "content": "",
                    "flag": "-H"
                },
                {
                    "name": "-l",
                    "content": "device. The request is sent via a SEND DIAGNOSTIC command (with the \"pf\" bit set)  and\nthe  response is fetched by a RECEIVE DIAGNOSTIC RESULTS command. When used in the ab‐\nsence of a DEVICE argument then a list of diagnostic page  names  and  their  numbers,\nknown by this utility, are listed.\n",
                    "flag": "-l"
                },
                {
                    "name": "-N --new",
                    "content": "Switch to the newer style options.\n",
                    "flag": "-N",
                    "long": "--new"
                },
                {
                    "name": "-pf",
                    "content": "given in which case the Page Format bit is set (as required by SPC-3).\n"
                },
                {
                    "name": "-raw",
                    "content": "string of comma separated hex numbers each of which should resolve  to  a  byte  value\n(i.e.  0  to  ff inclusive). This sequence forms a diagnostic page to be sent with the\nSCSI SEND DIAGNOSTIC command. Mostly likely the -pf option should also be given.\n"
                },
                {
                    "name": "-raw=-",
                    "content": "(newline) separated. If a line contains \"#\" then the remaining characters on that line\nare  ignored.  Otherwise  each  non separator character should resolve to a byte value\n(i.e. 0 to ff inclusive). This sequence forms a diagnostic page to be  sent  with  the\nSCSI SEND DIAGNOSTIC command. Mostly likely the -pf option should also be given.\n"
                },
                {
                    "name": "-s",
                    "content": "selects a background short self-test; 2 selects a background extended self-test; 5 se‐\nlects a foreground short self-test; 6 selects a foreground extended test. A value of 4\nwill  abort  a (background) self-test that is in progress. This option is mutually ex‐\nclusive with default self-test (i.e. -t).\n",
                    "flag": "-s"
                },
                {
                    "name": "-t",
                    "content": "option  should  not  be active together with this option.  Both the -doff and/or -uoff\noptions can be used with this option.\n",
                    "flag": "-t"
                },
                {
                    "name": "-T",
                    "content": "where SECS is a timeout value (in seconds) for foreground  self-test  operations.  See\nthe --timeout=SECS option above.\n",
                    "flag": "-T"
                },
                {
                    "name": "-uoff",
                    "content": "main description.\n"
                },
                {
                    "name": "-v",
                    "content": "",
                    "flag": "-v"
                },
                {
                    "name": "-V",
                    "content": "-?     output usage message. Ignore all other parameters.\n",
                    "flag": "-V"
                }
            ]
        },
        "EXAMPLES": {
            "content": "The examples sub-directory in the sg3utils packages contains two example scripts  that  turn\non  the CJTPAT (jitter pattern) on some SAS disks (one script for each phy). One possible in‐\nvocation for phy 1 is:\n\nsgsenddiag --pf --raw=- /dev/sg2 < sdiagsasp1cjtpat.txt\n\nThere is also an example script that turns on the IDLE pattern. Once a test pattern has  been\nstarted it can be turned off by resetting the phy or with the STOP phy pattern function:\n\nsgsenddiag --pf --raw=- /dev/sg2 < sdiagsasp1stop.txt\n",
            "subsections": []
        },
        "ENVIRONMENT VARIABLES": {
            "content": "Since  sg3utils  version 1.23 the environment variable SG3UTILSOLDOPTS can be given. When\nit is present this utility will expect the older command line options.  So  the  presence  of\nthis  environment variable is equivalent to using --old (or -O) as the first command line op‐\ntion.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Written by Douglas Gilbert\n",
            "subsections": []
        },
        "REPORTING BUGS": {
            "content": "Report bugs to <dgilbert at interlog dot com>.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright © 2003-2018 Douglas Gilbert\nThis software is distributed under the GPL version 2. There is NO warranty; not even for MER‐\nCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "",
            "subsections": [
                {
                    "name": "sg_ses(8), sg_logs(8), smartmontools(see net)",
                    "content": "sg3utils-1.43                                May 2018                                SGSENDDIAG(8)"
                }
            ]
        }
    },
    "summary": "sgsenddiag - performs a SCSI SEND DIAGNOSTIC command",
    "flags": [
        {
            "flag": "-d",
            "long": "--doff",
            "arg": null,
            "description": "set the Device Offline (DevOffL) bit (default is clear). Only significant when --test option 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."
        },
        {
            "flag": "-e",
            "long": "--extdur",
            "arg": null,
            "description": "outputs the expected extended self-test duration. The duration is given in seconds (and minutes in parentheses). This figure is obtained from mode page 0xa (i.e. the control mode page)."
        },
        {
            "flag": "-h",
            "long": "--help",
            "arg": null,
            "description": "print usage message then exit."
        },
        {
            "flag": "-H",
            "long": "--hex",
            "arg": null,
            "description": "outputs response from RECEIVE DIAGNOSTIC RESULTS in hex rather than decode it. Only the Supported Diagnostic Pages diagnostic page (i.e. pagecode=0) is decoded; other pages (e.g. those used by SES) are output in hex. If --hex is used once, the hex output has a relative address at the start of each line. If --hex is used twice, then ASCII is shown to the right of each line of hex. If --hex is used three time 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."
        },
        {
            "flag": "-l",
            "long": "--list",
            "arg": null,
            "description": "when a DEVICE is 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 ab‐ sence of a --list argument then a list of diagnostic page names and their numbers, known by this utility, are listed."
        },
        {
            "flag": "-m",
            "long": "--maxlen",
            "arg": null,
            "description": "where LEN is 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 is 4096 bytes. LEN cannot exceed 65535 or 0xffff in hexadecimal."
        },
        {
            "flag": "-O",
            "long": "--old",
            "arg": null,
            "description": "Switch to older style options. Please use as first option."
        },
        {
            "flag": "-P",
            "long": "--page",
            "arg": null,
            "description": "where PG is 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 DIAG‐ NOSTIC command is sent (unlike --list). If PG is 0 then the response is decoded as if it is the SPC Supported Diagnostic pages diagnostic page. Other PG values (i.e. 1 to 255) have their responses output in hex."
        },
        {
            "flag": "-p",
            "long": "--pf",
            "arg": null,
            "description": "set Page Format (PF) bit. By default it is clear (i.e. 0) unless the list --list op‐ tion is given in which case the Page Format bit is set (as required by SPC-3)."
        },
        {
            "flag": "-r",
            "long": "--raw",
            "arg": null,
            "description": "string of comma separated hex numbers each of which should resolve to a byte value (i.e. 0 to ff inclusive). A (single) space separated string of hex bytes is also al‐ lowed 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 --pf option should also be given."
        },
        {
            "flag": "-r",
            "long": "--raw",
            "arg": "-",
            "description": "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. 0 to ff inclusive). This sequence forms a diagnostic page to be sent with the SCSI SEND DIAGNOSTIC command. Mostly likely the --pf option should also be given."
        },
        {
            "flag": "-s",
            "long": "--selftest",
            "arg": null,
            "description": "where ST is the self-test code. The default value is 0 which 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)."
        },
        {
            "flag": "-t",
            "long": "--test",
            "arg": null,
            "description": "sets the default Self Test (SelfTest) bit. By default this is clear (0). The --selftest=ST option should not be active together with this option. Both the --doff and/or --uoff options can be used with this option."
        },
        {
            "flag": "-T",
            "long": "--timeout",
            "arg": null,
            "description": "where SECS is a timeout value (in seconds) for foreground self-test operations. The default value is 7200 seconds (2 hours) and any values of SECS less than the default are ignored."
        },
        {
            "flag": "-u",
            "long": "--uoff",
            "arg": null,
            "description": "set the Unit Offline (UnitOffL) bit (default is clear). Only significant when --test option 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."
        },
        {
            "flag": "-v",
            "long": "--verbose",
            "arg": null,
            "description": "increase level of verbosity. Can be used multiple times."
        },
        {
            "flag": "-V",
            "long": "--version",
            "arg": null,
            "description": "print out version string then exit."
        }
    ],
    "examples": [
        "The examples sub-directory in the sg3utils packages contains two example scripts  that  turn",
        "on  the CJTPAT (jitter pattern) on some SAS disks (one script for each phy). One possible in‐",
        "vocation for phy 1 is:",
        "sgsenddiag --pf --raw=- /dev/sg2 < sdiagsasp1cjtpat.txt",
        "There is 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:",
        "sgsenddiag --pf --raw=- /dev/sg2 < sdiagsasp1stop.txt"
    ],
    "see_also": []
}