Get a given date and subtract it to 5 days ago


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get a given date and subtract it to 5 days ago
# 1  
Old 02-13-2018
Get a given date and subtract it to 5 days ago

Hi all,

I have been researching to obtain SSL certification expiry for most of our webistes. For some cases, some hosts where not directly accessible so i finally got a solution working with curl using my proxy. This lists the expiry date which i'm finally looking for.

Code:
[matt@server]# curl --proxy http://x.x.x.x:xxxx --insecure -v https://matt.com/ 2>&1 | awk 'BEGIN { cert=0 } /^\* SSL connection/ { cert=1 } /^\*/ { if (cert) print }' | grep "expire date"
*       expire date: Feb 13 23:59:59 2019 GMT

The next step is to try to find a way to get notified 5 days before that date (no emails).

First thoughts are to extract the date using awk/sed from the above result and convert it to epoch:

Code:
 date --date="13-Feb-19" +%s
1550012400

Then i was thinking to somehow subtract this date to 5 days ago and convert it to epoch time. With both values in hand i subtract and the difference will be the said threshold. if less then, it means less then 5 days prior to expiry.
However i don't see how we can get a GIVEN date and subtract.
Do you have some thoughts or maybe other ideas?

Rgds,

Matthew
# 2  
Old 02-13-2018
You didn't mention your OS nor date versions, but your usage of date --date= leads me to infer
Code:
date --date="13-Feb-19 -5days"
Fr 8. Feb 00:00:00 CET 2019

might work on your system. Would that help?

Other idea: If you have an electronic / online calender, get the expiry date once and enter it into that calender.
# 3  
Old 02-13-2018
Code:
today_plus_5=$(date --date="today + 5 days" +%s)
expire=$(date --date="13-Feb-19" +%s)
if [ $today_plus_5 -ge $expire ]; then echo "will expire in 5 days"; fi

Or
Code:
today=$(date +%s)
expire_minus_5=$(date --date="13-Feb-19 - 5 days" +%s)
if [ $today -ge $expire_minus_5 ]; then echo "will expire in 5 days"; fi

# 4  
Old 02-14-2018
Gnu date will be able to parse the initial expiry date string, ie Feb 13 23:59:59 2019 GMT without the need to munge it into, eg 13-Feb-19. All the suggestions in the above examples should work just as well with that initial string.

Andrew
# 5  
Old 02-15-2018
Hi,

Thanks everybody for the replies. The "-5days" part is what i was missing!

Yes Andrew, you don't need to munge it at all.

Rgds
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

2. UNIX for Beginners Questions & Answers

How to find a file that's modified more than 2 days ago but less than 5 days ago?

How to find a file that's modified more than 2 days ago but was modified less than 5 days ago by use of any Linux utility ? (4 Replies)
Discussion started by: abdulbadii
4 Replies

3. Shell Programming and Scripting

Subtract months/days from date

Hi, Can you please let me know code for the below (in korn shell) a) Subtract month(s) from given date b) Subtract day(s) from give date c) Subtract month(s) from given timestamp d) Subtract day(s) from give timestamp (1 Reply)
Discussion started by: tostay2003
1 Replies

4. Shell Programming and Scripting

Subtract 2 date columns in .csv file and get output as number of days

Hi, I have one .csv file. I have 2 date columns present in file, column 2 and column 3. I need to calculate how many days exist between 2 dates. I am trying to subtract date column 2 from date column 3. Eg: my file look likes s.no, Start_date,End_Date 1, 7/29/2012,10/27/2012 2,... (9 Replies)
Discussion started by: Dimple
9 Replies

5. UNIX for Advanced & Expert Users

Subtract days to a date in AIX 5.3

good afternoon, can someone help me, I need to make a script where n subtract days to a date. I am using AIX 5.3. Greetings. (4 Replies)
Discussion started by: systemoper
4 Replies

6. Shell Programming and Scripting

Calculating 7 days ago date for the given Argument

Hi I have shell script and I am facing the below issue to integrate the date calculation to the the script. If I give the $1 as the date(20110701) then I need to get the 7 days ago date for the same format.(20110624). At first I thought its a simple one to handle and I did a search in the... (10 Replies)
Discussion started by: filter
10 Replies

7. Shell Programming and Scripting

Date within a timeframe 2 days ago

How could I using the following example, change it to show 2 days ago within the same time frame 0600 AM to 0600 AM let foo=`date "+(1%H-106)*60+1%M-100"` bar=foo+1440 find . -mmin +$foo -mmin -$bar | tr -s '/','-' '^' | cut -f2,3 -d"^" | tr -s '^' ' ' | Please use code tags (7 Replies)
Discussion started by: freddie999
7 Replies

8. Shell Programming and Scripting

how to get what date was 28 days ago of the current system date IN UNIX

Hi, Anybody knows how to get what date was 28 days ago of the current system date through UNIX script. Ex : - If today is 28th Mar 2010 then I have to delete the files which arrived on 1st Mar 2010, (15 Replies)
Discussion started by: kandi.reddy
15 Replies

9. Shell Programming and Scripting

Subtract days from a variable holding date

Hi, could someone help on this.. I have a date in variable procdate="05/30/2009" I would want to Subtract it with 3 or 4 (2 Replies)
Discussion started by: infernalhell
2 Replies

10. Shell Programming and Scripting

date for two days or 3 days ago

i need a script that can tell me the date 2 days ago or 3 days ago. please help (7 Replies)
Discussion started by: tomjones
7 Replies
Login or Register to Ask a Question