Solved

ASH get date 7 days agao

Posted on 2013-12-16
5
400 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
  • 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 500 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now