Solved Date formatting problems

nebu

New Member

Reaction score: 1
Messages: 9

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
 

xavi

Active Member

Reaction score: 79
Messages: 116

Check that the same shell and the same locale are being used on both machines.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 6,926
Messages: 28,850

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.
 
OP
OP
N

nebu

New Member

Reaction score: 1
Messages: 9

You are right! Removing the german locale does the trick.

Thank you very much!
 

Vovas

Member

Reaction score: 2
Messages: 52

Hi,
I've tried to use same script and same error. Do you mean delete locale from /etc/login.conf?
 
Top