SG_TIMESTAMP(8)
π Manual: sg_timestamp, section 8, from SG3_UTILS π¦
β¨ NAME β¨
okay so sg_timestamp is the tool that lets you report or set the timestamp on a SCSI device π
β¨ SYNOPSIS β¨
sg_timestamp [--elapsed] [--help] [--hex] [--milliseconds=MS]
[--no-timestamp] [--origin] [--raw] [--readonly] [--seconds=SECS]
[--srep] [--verbose] [--version] DEVICE
β¨ DESCRIPTION β¨
bestie, this thing sends a SCSI REPORT TIMESTAMP or SET TIMESTAMP command to the DEVICE π
Both of these commands live in the SPC-5 draft standard revision 7 (spc5r07.pdf), so you know it's legit π₯
if you give either --milliseconds=MS or --seconds=SECS (but you can't give both, no cap) then it sends SET TIMESTAMP. otherwise it sends REPORT TIMESTAMP β¨
the timestamp goes to and from the DEVICE as the number of milliseconds since the epoch, which is 1970-01-01 00:00:00 UTC π it's stored in a 48 bit unsigned integer, and it's giving very specific. Unix machines use that same epoch too, except they usually count in seconds instead π§ The Unix date command, especially its "+%s" format, is seriously iconic for converting to and from timestamps and making them readable for humans. check the EXAMPLES section below π
there's also a companion utility called sg_sat_datetime that has similar options and lets you get or set the date and time on an ATA device (usually a SATA disk) π«Ά it sends its ATA commands through the SCSI to ATA Translation (SAT) layer.
β¨ OPTIONS β¨
ok the rule here is that arguments to long options are required for short options too π
-e,--elapsedβ treats the timestamp in REPORT TIMESTAMP as an elapsed time since something like a power cycle or hard reset, and formats it as<n> days hh:mm:ss.xxx.hhis hours (00 to 23 inclusive),mmis minutes (00 to 59 inclusive),ssis seconds (00 to 59 inclusive), andxxxis milliseconds (000 to 999 inclusive). if the number of days is 0, the0 dayspart gets skipped unless you pass this option two or more times π-h,--helpβ prints the usage message and then exits πΈ-H,--hexβ prints the REPORT TIMESTAMP response in ASCII hexadecimal to stderr. nothing gets decoded, it's raw vibes π₯-m,--milliseconds=MSβMSis the number of milliseconds since 1970-01-01 00:00:00 UTC that you want to set on theDEVICEwith the SCSI SET TIMESTAMP command β¨-N,--no-timestampβ when REPORT TIMESTAMP runs, this option stops the timestamp value (in seconds or milliseconds) from being printed. it can help declutter the output when you're trying to figure out the timestamp origin (see the--originoption) π§-o,--originβ the REPORT TIMESTAMP response has a "timestamp origin" field in it. with this option, that field gets decoded and printed before the timestamp value. by default it doesn't get printed at all π T10 describes this field as "the most recent event that initialized the returned device clock". a value of 0 means a power up or hard reset initialized the clock, 2 means a SET TIMESTAMP initialized it, and 3 means some other method did π¦ if you use it once, you get a descriptive string on a line before the timestamp value. if you use it twice, you get the TIMESTAMP ORIGIN value in decimal (somewhere between 0 and 7 inclusive). if you use it three times, you get a line that looks likeTIMESTAMP_ORIGIN=<value>π-r,--rawβ dumps the SCSI REPORT TIMESTAMP response (the data-out buffer) in binary to stdout. heads up,--originand--srepget ignored when you use this one. all the error and verbose messages go to stderr too π-R,--readonlyβ opens theDEVICEread-only. the default is read-write π«Ά-s,--seconds=SECSβSECSis the number of seconds since 1970-01-01 00:00:00 UTC that you want to set on theDEVICEwith the SCSI SET TIMESTAMP command.SECSgets multiplied by 1000 before it's used in SET TIMESTAMP π-S,--srepβ reports the number of seconds since 1970-01-01 00:00:00 UTC. it does this by dividing the value from the SCSI REPORT TIMESTAMP command by 1000 π-v,--verboseβ turns up the verbosity, aka debug output π-V,--versionβ prints the version string and then exits β
β¨ EXIT STATUS β¨
sg_timestamp exits with 0 when it works. otherwise, check out the sg3_utils(8) man page for the rest π
β¨ NOTES β¨
the TCMOS and SCSIP bits in the Control extension mode page (see sdparm) change how the timestamp held by a DEVICE behaves π₯
right now, only the "Utilization usage rate based on date and time" parameters in the Utilization log page (sbc4r09.pdf) use timestamps. check out the sg_logs utility for that. vendor specific commands and pages might use timestamps too, so keep an eye out π
β¨ EXAMPLES β¨
on Unix machines (like Linux, FreeBSD and Solaris) the date command is super useful when you're dealing with timestamps π
to grab the timestamp from a DEVICE and show it in a human-readable form, you could do something like this π¦
# sg_timestamp -S /dev/sdb
1448993950
# date --date=@1448993950
Tue Dec 1 13:19:10 EST 2015
# date -R --date="@1448993950"
Tue, 01 Dec 2015 13:19:10 -0500
the last two date commands show two different looks for the same date (aka 1448993950 seconds since 1970-01-01 00:00:00 UTC) πΈ you can also mash sg_timestamp and date together with backquotes:
# date -R --date=@`sg_timestamp -S /dev/sdc`
Wed, 16 Dec 2015 20:12:59 -0500
to set the timestamp on the DEVICE to roughly right now, you could do this π§
# date +%s
1448993955
# sg_timestamp --seconds=1448993955 /dev/sdb
and you can squish those two command lines into one with backquotes too π
# sg_timestamp --seconds=`date +%s` /dev/sdb
β¨ AUTHORS β¨
written by Douglas Gilbert, the legend himself π
β¨ REPORTING BUGS β¨
send bugs to <dgilbert at interlog dot com> π
β¨ COPYRIGHT β¨
Copyright Β© 2015-2018 Douglas Gilbert this software is distributed under a BSD-2-Clause license. there is NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE π
β¨ SEE ALSO β¨
sdparm(sdparm), sg_logs(sg3_utils), sg_sat_datetime(sg3_utils) π«Ά
bestie, that's the whole tea β this is sg3_utils 1.43 from April 2018, and it's a whole vibe πππ¦
π¦ where this page comes from
- alpine 3.24: sg3_utils-doc 1.48-r0 Β· BSD-2-Clause AND GPL-2.0-or-later
- arch rolling: sg3_utils 1.49-1 Β· GPL-2.0-or-later AND BSD-2-Clause
- centos-stream 10: sg3_utils 1.48-11.el10 Β· GPL-2.0-or-later AND BSD-2-Clause
- debian trixie: sg3-utils 1.48-3~deb13u1
- fedora 43: sg3_utils 1.48-10.fc43 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 43: sg3_utils 1.48-6.fc43 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 44: sg3_utils 1.48-10.fc44 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 44: sg3_utils 1.48-8.fc44 Β· GPL-2.0-or-later AND BSD-2-Clause
- nixos 26.05: sg3_utils 1.48
- nixpkgs unstable: sg3_utils 1.49
- ubuntu questing: sg3-utils 1.48-2ubuntu1
- ubuntu resolute: sg3-utils 1.48-3ubuntu3
- ubuntu resolute: sg3-utils 1.48-3ubuntu3.2
- ubuntu stonking: sg3-utils 1.48-3ubuntu5
- π girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms