Skip to content

Instantly share code, notes, and snippets.

@lanceliao
Last active October 4, 2015 04:53
Show Gist options
  • Save lanceliao/cb57f7d852794e1736d6 to your computer and use it in GitHub Desktop.
Save lanceliao/cb57f7d852794e1736d6 to your computer and use it in GitHub Desktop.
record SSD smart status to a file on startup and suspend
[Unit]
Description=Record SSD smart status
Before=suspend.target
[Service]
Type=oneshot
ExecStart=/opt/scripts/ssd-monitor.sh
RemainAfterExit=no
[Install]
WantedBy=sleep.target multi-user.target
2015-10-04 10:39:04 56 32h+52m+07.640s 38 269.469 GB 197.531 GB 240 GB
2015-10-04 10:39:06 56 32h+52m+07.860s 38 269.469 GB 197.531 GB 240 GB
2015-10-04 10:39:07 56 32h+52m+07.900s 38 269.469 GB 197.531 GB 240 GB
#!/bin/sh
# @Author: lance
# @Date: 2015-10-04 02:36:35
# @Last Modified by: lance
# @Last Modified time: 2015-10-04 10:38:46
# @Description Save SSD status in a file
# deine the ssd list
ssd_list=(sda sdb)
# dedine where to save the records
rec_path=/var/lib/ssd
my_date=$(date "+%Y-%m-%d %H:%M:%S" )
for ssd in "${ssd_list[@]}"; do
ssd_status=$(smartctl -a /dev/$ssd)
power_cycle=$(echo "${ssd_status}"| awk '/^ 12/ {print $10 } ')
power_time=$(echo "${ssd_status}" | awk '/^ 9/ {print $10 } ')
temp=$(echo "${ssd_status}"| awk '/Temperature_/ {print $10 } ') #Reg of temp maybe 190 or 192
total_write=$(echo "${ssd_status}" | awk '/^241/ {print $10 * 32 / 1024, "GB" } ')
total_read=$(echo "${ssd_status}" | awk '/^242/ {print $10 * 32 / 1024, "GB" } ')
nand_write=$(echo "${ssd_status}" | awk '/^249/ {print $10, "GB" } ')
mkdir -p $rec_path
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$my_date" "$power_cycle" "$power_time" "$temp" "$total_write" "$total_read" "$nand_write" >> "${rec_path}/${ssd}.xls"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment