Solved

ASH get date 7 days agao

Posted on 2013-12-16
5
415 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…

691 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