?
Solved

ASH get date 7 days agao

Posted on 2013-12-16
5
Medium Priority
?
420 Views
Last Modified: 2013-12-16
Hello.

In my bash scripts I can do:

DAY7=`date -I -d "7 days ago"`

When doing this in ash on my synology diskstation I get:

date: invalid date '7 days ago'


Is there any other way to do this that would work on ash?
0
Comment
Question by:pucko73
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Author Comment

by:pucko73
ID: 39720949
date -- help shows:

-d,--date TIME  Display TIME, not 'now'
0
 
LVL 19

Accepted Solution

by:
simon3270 earned 2000 total points
ID: 39722540
I think it's not the shell, it's that your "date" command on your diskstation doesn't have the GNU extensiosn such as "7 days ago".

if you can use Perl, how about:
perl -MPOSIX -e 'print POSIX:strftime("%Y-%m-%d\n", localtime(time-(7*24*60*60)))'

Open in new window

(with the caveat that this doesn't necessarily cope in the week that daylight savings starts and stops, if it is called just before or after midnight)
0
 
LVL 16

Expert Comment

by:Joseph Gan
ID: 39722592
ash is very limited, it doesn't support additional functionality as bash does.
0
 

Author Comment

by:pucko73
ID: 39722642
[admin@DiskStation admin]$ perl -MPOSIX -e 'print POSIX:strftime("%Y-%m-%d\n", l
ocaltime(time-(7*24*60*60)))'
syntax error at -e line 1, near "POSIX:"
Execution of -e aborted due to compilation errors.
[admin@DiskStation admin]$
0
 
LVL 19

Expert Comment

by:simon3270
ID: 39722695
Ah, that's what comes of trying to write and test the code on one machine, and copy it to another!

There should be two colons in POSIX::strftime, so the whole line is:
$ perl -MPOSIX -e 'print POSIX::strftime("%Y-%m-%d\n", localtime(time-(7*24*60*60)))'
2013-12-09
$ date
Mon Dec 16 22:20:18 GMT 2013
$ 

Open in new window

0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question