Help with old bash script. I have a gnu date issue. Going from Solaris to TrueNAS

textex

Dabbler
Joined
Aug 7, 2021
Messages
10
I've just converted all of my storage from Solaris systems to TrueNas.

I should say I am a complete UNIX/Linux newbie, and survive by mimicking other's scripts.

All is well, except my main backup script has a gnu date call that BSD can't process. I have 10 years of snapshots using this naming scheme and I'd prefer to get the script working rather than renaming everything on multiple pools.

I've attached the form script (ip addresses and pool names deleted) for review. The offending line is #19:

yesterday=`/usr/gnu/bin/date -d"yesterday" +"$type-%Y-%m-%d"`

BSD can't process the /usr/gnu/date portion. Is there a BSD equivalent? I've thought about adding gnu date to TrueNas, but folks seem to advise against adding packages to the base system.

Any suggestions are welcome.
 

Attachments

  • SenRecScript.txt
    1.4 KB · Views: 137

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
Welcome to the forums.

It's unfortunate that the first exposure many people have to UNIX shell scripting are the awful GNU tools. Particularly galling are all the people who write "/bin/sh" scripts with BASH-isms littered throughout, but other stuff like extensions to commands are a problem too.

Unfortunately, POSIX doesn't have the necessary extensions to do this for the date command, so if you wanted to do this in a truly portable way, you would probably need to call a perl snippet. However, if you are looking for a FreeBSD equivalent to the GNU badness, FreeBSD has its own badness with "date -v"; try "date -v -1d" for example to print the current time minus one day. The strftime stuff should be similar or identical; you can check out the man page for date with "man date" from the command line.
 

textex

Dabbler
Joined
Aug 7, 2021
Messages
10
Thanks. I'll give it a go. I'm not a great Unix or Linux guy or I'd write something better. My programming ability comes from trying Basic on a TRS-80 about 40 years ago...
 

textex

Dabbler
Joined
Aug 7, 2021
Messages
10
Well, no luck.

I got:

-1dyesterday: Cannot apply date adjustment
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]
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
You shouldn't have a "yesterday" in there, that's a GNU thing.
 

textex

Dabbler
Joined
Aug 7, 2021
Messages
10
I tried it without the "yesterday" and got:

-1d+-%Y-%m-%d: Cannot apply date adjustment
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]

To any BSD date experts - help is welcome...
 

Heracles

Wizard
Joined
Feb 2, 2018
Messages
1,401
Try just this :
date -v -24H

That will return the date as it was 24H ago...
 

Mark Levitt

Explorer
Joined
May 21, 2017
Messages
56
I tried it without the "yesterday" and got:

-1d+-%Y-%m-%d: Cannot apply date adjustment
To any BSD date experts - help is welcome...

You need a space between the "d" and the rest of the line:
date -v -1d +-%Y-%m-%d

outputs
-2021-08-23
 
Top