edgarsuit / FreeNAS-Report

SMART & ZPool Status Report for FreeNAS
GNU General Public License v3.0
113 stars 45 forks source link

date: illegal option #8

Closed sehang closed 3 years ago

sehang commented 5 years ago
./report.sh
date: illegal option -- 0
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]

My FreeNAS version is FreeBSD ANGELING.PORING.NET 11.0-STABLE FreeBSD 11.0-STABLE #0 r321665+25fe8ba8d06(freenas/11.0-stable): Mon Sep 25 06:24:11 UTC 2017 root@gauntlet:/freenas-11-releng/freenas/_BE/objs/freenas-11-releng/freenas/_BE/os/sys/FreeNAS.amd64 amd64

edgarsuit commented 5 years ago

Known issue, haven't had time to fix it yet. Your scrub time doesn't include a days entry so it messed up when it tries to parse it. It should be an easy fix, I just haven't gotten around to it.

sehang commented 5 years ago

The zpool status returns

pool: freenas-boot
 state: ONLINE
  scan: scrub repaired 0 in 0h0m with 0 errors on Fri Jan 11 03:45:08 2019

I have revised the script to parse the date format.

    statusOutput="$(zpool status "$pool")"
    if [ "$(echo "$statusOutput" | grep "scan" | awk '{print $2}')" = "scrub" ]; then
        scrubRepBytes="$(echo "$statusOutput" | grep "scan" | awk '{print $4}')"
        scrubErrors="$(echo "$statusOutput" | grep "scan" | awk '{print $8}')"
        # Convert time/datestamp format presented by zpool status, compare to current date, calculate scrub age
        scrubDate="$(echo "$statusOutput" | grep "scan" | awk '{print $15"-"$12"-"$13"_"$14}')"
        scrubTS="$(date -j -f "%Y-%b-%e_%H:%M:%S" "$scrubDate" "+%s")"
        currentTS="$(date "+%s")"
        scrubAge=$((((currentTS - scrubTS) + 43200) / 86400))
        scrubTime="$(echo "$statusOutput" | grep "scan" | awk '{print $6}')"
    fi
mojo1988 commented 3 years ago

Hey, same issue with TrueNas Core TrueNAS-12.0-U2

Updated a few days ago. On Freenas 11.3 script works fine.

date: illegal option -- 0 usage: date [-jnRu] [-d dst] [-r seconds|file] [-t west] [-v[+|-]val[ymwdHMS]] [-I[date | hours | minutes | seconds]] [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format] date: illegal option -- 0 usage: date [-jnRu] [-d dst] [-r seconds|file] [-t west] [-v[+|-]val[ymwdHMS]] [-I[date | hours | minutes | seconds]] [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format] date: illegal option -- 0 usage: date [-jnRu] [-d dst] [-r seconds|file] [-t west] [-v[+|-]val[ymwdHMS]] [-I[date | hours | minutes | seconds]] [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]

otherjoel commented 3 years ago

Can you update to the latest version of the script and see if it fixes this problem?

mojo1988 commented 3 years ago

Hey @otherjoel Thanks for the fix. No problems anymore