Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- Main() {
- export PATH=/bin:/usr/bin:/opt/local/bin:/usr/local/bin
- PathToSmartCtl="$(GetSmartCtl)"
- PathToKeys="${0%/*}"/keys
- CreateShellAlias
- sleep 1
- IsShiftPressed=$("${PathToKeys}" shift)
- IsOptionPressed=$("${PathToKeys}" option)
- case ${IsShiftPressed} in
- 1)
- # shift is pressed, we are in test mode!
- # if option is pressed as well we're
- # performing a long test otherwise short
- if [ "X${IsOptionPressed}" = "X1" ]; then
- TestMode=long
- else
- TestMode=short
- fi
- GetListOfVolumes | while read ; do
- # check whether device is SMART capable
- "${PathToSmartCtl}" -a ${REPLY} >/dev/null 2>&1
- if [ $? -eq 0 ]; then
- echo -e "${AbstandSchraddel}Previous test results for ${REPLY}:\n"
- "${PathToSmartCtl}" -l selftest ${REPLY}
- echo -e "\nNow performing a ${TestMode} test on ${REPLY} in the background. You can close this window and try again in several minutes. Please see below the smartctl output.\n"
- "${PathToSmartCtl}" -t ${TestMode} ${REPLY}
- AbstandSchraddel="\n\n\n"
- fi
- done
- ;;
- *)
- # we simply display SMART status for all devices
- GetListOfVolumes | while read ; do
- echo -e "${AbstandSchraddel}Examining ${REPLY}\n"
- "${PathToSmartCtl}" -a ${REPLY}
- AbstandSchraddel="\n\n\n"
- done
- ;;
- esac
- } # Main
- CreateShellAlias() {
- if [ -f "${HOME}/.profile" ]; then
- MyTmpFile="$(mktemp /tmp/${0##*/}.XXXXXX || (echo -e "Not able to create temporary file below /tmp/. Skip creating shell alias." | logger ; return))"
- trap "rm -f \"${MyTmpFile}\"; exit 0" 0 1 2 3 15
- grep -v "^alias smartctl" <"${HOME}/.profile" >"${MyTmpFile}"
- echo -e "alias smartctl=\"${PathToSmartCtl}\"" >>"${MyTmpFile}"
- cat "${MyTmpFile}" >"${HOME}/.profile"
- else
- echo -e "alias smartctl=\"${PathToSmartCtl}\"" >>"${HOME}/.profile"
- fi
- } # CreateShellAlias
- GetListOfVolumes() {
- /usr/sbin/diskutil list | grep "^/dev/" | while read ; do
- /usr/sbin/diskutil corestorage info ${REPLY} >/dev/null 2>&1 || echo ${REPLY}
- done
- } # GetListOfVolumes
- GetSmartCtl() {
- mdfind "kMDItemCFBundleIdentifier == 'de.kaiser-edv.k-smart'" | grep "\.app$" | while read ; do
- SmartCtlVersion=$("${REPLY}"/Contents/Resources/smartctl | awk -F" " '/^smartctl / {print $2}')
- echo -e "${SmartCtlVersion}\t${REPLY}/Contents/Resources/smartctl"
- done | sort -r | head -n1 | cut -f2
- } # GetSmartCtl
- Main "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement