Solved

ASH get date 7 days agao

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

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…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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…
Suggested Courses

738 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