DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2010-08-31 04:25:43

ameyer
Member
Registered: 2010-08-26
Posts: 10

Date Commands - Displaying "last month"

==SOLVED==
Thanks KyleK!

How I solved it:
I just downloaded coreutils-6.12-1.tgz from http://inreto.de/dns323/fun-plug/0.5/packages/
and replaced /mnt/HD_a2/ffp/bin/date with bin/date from coreutils-6.12-1.tgz




Im trying to name a monthly backup as the month-year that it was from.

But I cant figure out how to echo last month's name. I googled it and none of the linux commands work in the 323's shell.

Thanks

Last edited by ameyer (2010-09-04 02:07:17)

Offline

 

#2 2010-08-31 09:51:37

scaramanga
Member
Registered: 2010-08-04
Posts: 251

Re: Date Commands - Displaying "last month"

Try this:

Code:

 date "+%B-%Y"

See here full description of format string: http://unixhelp.ed.ac.uk/CGI/man-cgi?date

Last edited by scaramanga (2010-08-31 09:53:57)


DNS-323 HW Rev. C1 FW 1.10 fun-plug 0.5
2 x WD10EARS-00Y5B1 in Standard mode (LCC set to 5 min; Aligned to 4K)
Transmission with Transmission Remote GUI

Offline

 

#3 2010-08-31 12:32:55

FunFiler
Member
Registered: 2010-05-23
Posts: 577

Re: Date Commands - Displaying "last month"

Personally, I always use YYYYMMDD if I am including a date in a file name. It sorts sequencially that way.


3 * (DNS-323 with 2 * 2TB) = 12TB Running FW v1.08 & FFP v0.5
Useful Links: Transmission, Transmission Remote, Automatic

Offline

 

#4 2010-08-31 13:31:19

scaramanga
Member
Registered: 2010-08-04
Posts: 251

Re: Date Commands - Displaying "last month"

FunFiler wrote:

Personally, I always use YYYYMMDD if I am including a date in a file name. It sorts sequencially that way.

I 2nd that. But that's what the guy (gal?) wanted - that's what he got.


DNS-323 HW Rev. C1 FW 1.10 fun-plug 0.5
2 x WD10EARS-00Y5B1 in Standard mode (LCC set to 5 min; Aligned to 4K)
Transmission with Transmission Remote GUI

Offline

 

#5 2010-08-31 14:54:23

ameyer
Member
Registered: 2010-08-26
Posts: 10

Re: Date Commands - Displaying "last month"

Thanks guys

But that is this month right? I'm looking for last month. ( so if it is Aug - It will output July)

Code:

date "+%B-%Y"

Last edited by ameyer (2010-08-31 15:02:37)

Offline

 

#6 2010-08-31 15:21:07

scaramanga
Member
Registered: 2010-08-04
Posts: 251

Re: Date Commands - Displaying "last month"

Oh dear, are you sure it's worth the trouble? Here's how you can do it.
1. Create a file prev_month.txt (one month name per line, starting from December till November) like so:

Code:

December
January
February
March
April
May
June
July
August
September
October
November

2. Take it for a spin. From the command line, test these commands:

Code:

/tmp # sed -n "1p" prev_month.txt
December
/tmp # sed -n "6p" prev_month.txt
May
/tmp # sed -n "12p" prev_month.txt
November

3. Now we need to get the current date. Try this:

Code:

/tmp # sed -n "$(date "+%m")p" prev_month.txt
July

4. Getting the year right (I bet you'd like to change Jan. 2011 to Dec. 2010):
I'll leave that as an exercise to you wink
Hint: Read here about Arithmetic Expressions and Flow-Control Constructs.

Last edited by scaramanga (2010-08-31 15:30:14)


DNS-323 HW Rev. C1 FW 1.10 fun-plug 0.5
2 x WD10EARS-00Y5B1 in Standard mode (LCC set to 5 min; Aligned to 4K)
Transmission with Transmission Remote GUI

Offline

 

#7 2010-08-31 15:40:17

ameyer
Member
Registered: 2010-08-26
Posts: 10

Re: Date Commands - Displaying "last month"

Oh man!
In Bash you can just do something like

Code:

date --date="last month" +%Y-%m

Thanks smile

Offline

 

#8 2010-08-31 15:52:23

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: Date Commands - Displaying "last month"

That's not a feature of bash, but of the 'date' command used. If it doesn't work for you, have a look at fonz' repositories, maybe he had a more 'complete' date.

Offline

 

#9 2010-08-31 18:28:39

karlrado
Member
Registered: 2009-12-07
Posts: 229

Re: Date Commands - Displaying "last month"

The optware date command works with "last month".


DNS-323 FW 1.07 : 2 1TB WD Caviar Green SATA : fun_plug: utelnet + optware (no ffp)

Offline

 

#10 2010-08-31 19:49:35

skydreamer
Member
From: At the Atlantic Coast
Registered: 2007-01-06
Posts: 232

Re: Date Commands - Displaying "last month"

I also had a look at it last night and managed to get previous month using the date command and expression evaluation $(( )) but stumbled on missing "leave out trailing 0" operator "-" in DNS-323 implementation which was confusing the integer maths: "%-m" does not work. And still the formula would have to be enhanced to include December last year when in January.
I would personally also vote for getting the latest "date" binary and use it in the simple script above.

Last edited by skydreamer (2010-08-31 19:49:56)

Offline

 

#11 2010-08-31 20:53:31

FunFiler
Member
Registered: 2010-05-23
Posts: 577

Re: Date Commands - Displaying "last month"

scaramanga wrote:

FunFiler wrote:

Personally, I always use YYYYMMDD if I am including a date in a file name. It sorts sequencially that way.

I 2nd that. But that's what the guy (gal?) wanted - that's what he got.

Sorry, didn't mean to sound like I was complaining, just wanted to offer the OP an option that may prove to be useful for them.

This is what I use in my shell scripts:

export cnd=`date +"%Y%m%d"`

The the variable "cnd" can be used throughout the script where required along with other actions.
Example
for i in "/home/d/*" ; do
  tar -P -rf /archive/$cnd.tar $i
done

Last edited by FunFiler (2010-08-31 20:58:20)


3 * (DNS-323 with 2 * 2TB) = 12TB Running FW v1.08 & FFP v0.5
Useful Links: Transmission, Transmission Remote, Automatic

Offline

 

#12 2010-09-04 00:59:38

KyleK
Member
From: Dresden, Germany
Registered: 2007-12-05
Posts: 1178

Re: Date Commands - Displaying "last month"

'date' is part of coreutils, which you can find here: http://inreto.de/dns323/fun-plug/0.5/packages/

fonz's version (6.12) does support "last month", although there are much newer releases of coreutils.

Offline

 

#13 2010-09-04 02:04:38

ameyer
Member
Registered: 2010-08-26
Posts: 10

Re: Date Commands - Displaying "last month"

Thanks! worked perfectly

How I solved it:
I just downloaded coreutils-6.12-1.tgz from http://inreto.de/dns323/fun-plug/0.5/packages/
and replaced /mnt/HD_a2/ffp/bin/date with bin/date from coreutils-6.12-1.tgz




KyleK wrote:

'date' is part of coreutils, which you can find here: http://inreto.de/dns323/fun-plug/0.5/packages/

fonz's version (6.12) does support "last month", although there are much newer releases of coreutils.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB