參考:徹底用 GNU/Linux 工做 - 29. 檢測硬碟 S.M.A.R.T. 健康狀態html
1.安裝python
sudo apt-get install smartmontools
2.查看硬盤的參數,須要得到Root權限linux
sudo smartctl -i /dev/sda smartctl 6.5 2016-01-24 r4214 [x86_64-linux-4.4.0-122-generic] (local build) Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org === START OF INFORMATION SECTION === Model Family: Samsung based SSDs Device Model: Samsung SSD 850 EVO 250GB Serial Number: S3LCNF0J807262K LU WWN Device Id: 5 002538 d42253d35 Firmware Version: EMT03B6Q User Capacity: 250,059,350,016 bytes [250 GB] Sector Size: 512 bytes logical/physical Rotation Rate: Solid State Device Form Factor: 2.5 inches Device is: In smartctl database [for details use: -P show] ATA Version is: ACS-2, ATA8-ACS T13/1699-D revision 4c SATA Version is: SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s) Local Time is: Mon May 7 10:14:29 2018 CST SMART support is: Available - device has SMART capability. SMART support is: Enabled
3.若是使用下面的Python腳原本調用該命令的時候,是須要得到Root權限的git
#!/usr/bin/python # !-*- coding:utf8 -*- import os def main(): dir = "~/桌面/test.sh" result = os.system("sh ~/桌面/test.sh") # print result if __name__ == '__main__': main()
能夠使用下面的方法來實現免輸入密碼,使用 sudo visudo 命令對/etc/sudoers文件增長下面設置vim
lintong ALL=(ALL) NOPASSWD: /usr/sbin/smartctl
注意不要使用vim等工具來進行修改,沒法修改錯的話可能會出現下面的錯誤bash
sudo: /etc/sudoers 中第 33 行附近有解析錯誤sudo: 沒有找到有效的 sudoers 資源,退出sudo: 沒法初始化策略插件
若是出現了的話,能夠使用Ubuntu啓動盤進入系統,在root用戶下將/etc/sudoers文件改回來就能夠了工具