Create or empty previous files and fix redirection

This commit is contained in:
Jeremy Gardais 2020-02-20 16:02:05 +01:00
parent 5ec0d0c8ee
commit b6c1913065
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 11 additions and 8 deletions

View File

@ -27,10 +27,11 @@ is_disk_support_smart() {
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG: is_disk_support_smart func check if SMART is supported on: ${_disk}." [ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG: is_disk_support_smart func check if SMART is supported on: ${_disk}."
if test -f "${_smarctl_support_result}"; then rm -f -- "${_smarctl_support_result}"; fi ## Create or empty previous file
true > "${_smarctl_support_result}"
## Grep only "support" lines from disk's informations ## Grep only "support" lines from disk's informations
smartctl -d "${_type}" -i -- "${_disk}" | grep -E "^SMART support is:" -- > "${_smarctl_support_result}" smartctl -d "${_type}" -i -- "${_disk}" | grep -E "^SMART support is:" -- >> "${_smarctl_support_result}"
## If the file is not empty ## If the file is not empty
if test -s "${_smarctl_support_result}"; then if test -s "${_smarctl_support_result}"; then
@ -80,11 +81,13 @@ choose_correct_type() {
} }
## }}} ## }}}
if test -f /tmp/dres; then rm -f -- /tmp/dres; fi # Create or empty previous files
if test -f /tmp/dscan; then rm -f -- /tmp/dscan; fi true > /tmp/dres
true > /tmp/dcheck
true > /tmp/dscan
# Get the list of all available devices # Get the list of all available devices
smartctl --scan > /tmp/dscan smartctl --scan >> /tmp/dscan
# TODO: Test if the file is not empty # TODO: Test if the file is not empty
if test -s /tmp/dscan; then if test -s /tmp/dscan; then
@ -136,10 +139,10 @@ if test -s /tmp/dscan; then
echo "" echo ""
echo "" echo ""
} >> /tmp/dres } >> /tmp/dres
done < /tmp/dscan > /tmp/dcheck done < /tmp/dscan >> /tmp/dcheck
else else
echo "1&red Error while scanning devices with smartctl" > /tmp/dcheck echo "1&red Error while scanning devices with smartctl" >> /tmp/dcheck
fi fi
# Set the global color according to the highest alert # Set the global color according to the highest alert