# sg_senddiag - performs a SCSI SEND DIAGNOSTIC command - man(8) - [phpMan]

[_SG_SENDDIAG_(8)](https://www.chedong.com/phpMan.php/man/SGSENDDIAG/8/markdown)                                SG3_UTILS                               [_SG_SENDDIAG_(8)](https://www.chedong.com/phpMan.php/man/SGSENDDIAG/8/markdown)

## 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
       This utility sends a SCSI SEND DIAGNOSTIC command to the _DEVICE_.  It  can  issue  self-tests,
       find supported diagnostic pages or send arbitrary diagnostic pages.

       When  the _--list_ option and a _DEVICE_ are given then the utility sends a SCSI RECEIVE DIAGNOS‐
       TIC RESULTS command to fetch the response (i.e.  the page  numbers  of  supported  diagnostic
       pages).

       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.

       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 out‐
       lines the second group of options.

## OPTIONS
       Arguments to long options are mandatory for short options as well.

### -d --doff
              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.

### -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  page  0xa  (i.e.  the
              control mode page).

### -h --help
              print usage message then exit.

### -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.
              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.

### -l --list
              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.

### -m --maxlen
              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.

### -O --old
              Switch to older style options. Please use as first option.

### -P --page
              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.

### -p --pf
              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).

### -r --raw
              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.

### -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.  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.

### -s --selftest
              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_).

### -t --test
              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.

### -T --timeout
              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.

### -u --uoff
              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.

### -v --verbose
              increase level of verbosity. Can be used multiple times.

### -V --version
              print out version string then exit.

## 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)](https://www.chedong.com/phpMan.php/man/sglogs/8/markdown)). The SCSI command timeout for this utility is set to 60 minutes to  al‐
       low for slow foreground extended self-tests.

       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.

       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 diag‐
       nostic page format). See the EXAMPLES section below.

       Arbitrary diagnostic pages can be read (in hex) with the [sg_ses(8)](https://www.chedong.com/phpMan.php/man/sgses/8/markdown) utility  (not  only  those
       defined in SES-2).

       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  de‐
       vices  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.

       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.

       To access SCSI enclosures see the [sg_ses(8)](https://www.chedong.com/phpMan.php/man/sgses/8/markdown) utility. sg_ses uses the SCSI SEND DIAGNOSTIC and
       RECEIVE DIAGNOSTIC RESULTS commands as outlined in the SES-2 (draft) standard.

## EXIT STATUS
       The exit status of sg_senddiag is 0 when it is successful. Otherwise see the [sg3_utils(8)](https://www.chedong.com/phpMan.php/man/sg3utils/8/markdown) man
       page.

## OLDER COMMAND LINE OPTIONS
       The  options  in  this section were the only ones available prior to sg3_utils version 1.23 .
       Since then this utility defaults to the newer command line options which can be overridden by
       using _--old_ (or _-O_) as the first option. See the ENVIRONMENT VARIABLES  section  for  another
       way to force the use of these older command line options.

### -doff  
              tion is set for the default self-test. Equivalent to _--doff_ in the main description.

### -e     
              description.

### -h     

### -H     

### -l     
              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 _DEVICE_ argument then a list of diagnostic page  names  and  their  numbers,
              known by this utility, are listed.

### -N --new
              Switch to the newer style options.

### -pf    
              given in which case the Page Format bit is set (as required by SPC-3).

### -raw
              string of comma separated hex numbers each of which 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.

### -raw=- 
              (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.

### -s
              selects a background short self-test; 2 selects a background extended self-test; 5 se‐
              lects a foreground short self-test; 6 selects a foreground extended test. A value of 4
              will  abort  a (background) self-test that is in progress. This option is mutually ex‐
              clusive with default self-test (i.e. _-t_).

### -t     
              option  should  not  be active together with this option.  Both the _-doff_ and/or _-uoff_
              options can be used with this option.

### -T
              where _SECS_ is a timeout value (in seconds) for foreground  self-test  operations.  See
              the _--timeout=SECS_ option above.

### -uoff  
              main description.

### -v     

### -V     

       **-?     **output usage message. Ignore 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 in‐
       vocation for phy 1 is:

         sg_senddiag --pf --raw=- /dev/sg2 < sdiag_sas_p1_cjtpat.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:

         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 is present this utility will expect the older command line options.  So  the  presence  of
       this  environment variable is equivalent to using _--old_ (or _-O_) as the first command line op‐
       tion.

## 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 MER‐
       CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

## SEE ALSO
### [sg_ses(8)](https://www.chedong.com/phpMan.php/man/sgses/8/markdown), [sg_logs(8)](https://www.chedong.com/phpMan.php/man/sglogs/8/markdown), smartmontools(see net)

sg3_utils-1.43                                May 2018                                [_SG_SENDDIAG_(8)](https://www.chedong.com/phpMan.php/man/SGSENDDIAG/8/markdown)
