Solved Date formatting problems

Hi,

I have a rather peculiar problem. I'm am using the zfshealth script from https://calomel.org/zfs_health_check_script.html on various machines to monitor the status of my zfs pool. So far, this worked fine.

The script checks if the last scrub date is longer than a week ago and uses date conversion to do so:

Code:
 ### FreeBSD with *nix supported date format
    scrubRawDate=$(/sbin/zpool status $volume | grep scrub | awk '{print $15 $12 $13}')
    scrubDate=$(date -j -f '%Y%b%e-%H%M%S' $scrubRawDate'-000000' +%s)


On a newly setup machine running FreeBSD 11.1 this gives me the following error:
Code:
2017Oct24
Failed conversion of ``2017Oct24-000000'' using format ``%Y%b%e-%H%M%S''
date: illegal time format
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]
./zfshealth.sh: arithmetic expression: expecting primary: "1508839134 - "

The exact same script runs flawlessly on a different box also running FreeBSD 11.1. Testing on the old machine:
Code:
root@hood:~ # uname -a
FreeBSD hood 11.1-RELEASE-p1 FreeBSD 11.1-RELEASE-p1 #0: Wed Aug  9 11:55:48 UTC 2017     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64

root@hood:~ # date -j -f '%Y%b%e-%H%M%S' 2017Oct24'-000000' +%s
1508796000
root@hood:~ #
Testing on the new one:

Code:
root@gorkon:~ # uname -a
FreeBSD gorkon 11.1-RELEASE-p1 FreeBSD 11.1-RELEASE-p1 #0: Wed Aug  9 11:55:48 UTC 2017     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64

root@gorkon:~ # date -j -f '%Y%b%e-%H%M%S' 2017Oct24'-000000' +%s
Failed conversion of ``2017Oct24-000000'' using format ``%Y%b%e-%H%M%S''
date: illegal time format
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]

What am I missing? Any ideas?

Regards,
Ben
 
I'm not sure if it's the case but %b is dependent on the locale settings. It's probably better to use the numeric representation of the month to prevent wrong interpretations.
 
Back
Top