We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

compare dates in shell script

zeraxis_ee
zeraxis_ee asked
on
Medium Priority
1,590 Views
Last Modified: 2012-05-06
I need to compare 2 dates (date now and one from a file) and if date now is 20 minutes more than the date in the file, the script needs to restart the browser.

cat lastplaylist    gives me the date in the file:Fri Feb 13 05:48:51 GMT 2009
date gives me date and time now: Fri Feb 13 08:48:51 GMT 2009

I know I can restart the browser by
killall firefox
firefox http://mywebsite.com

I just don't know how to compare the 2 dates and see the difference in minutes.

Could someone help?

Many thanks
Comment
Watch Question

sysadmin
CERTIFIED EXPERT
Commented:
1200 is 20 minutes in seconds.
#!/bin/sh
 
DATE_NOW=`date +%s`
DATE_FROM_FILE=`date -d "\`cat lastplaylist\`" +%s`
 
DATE_DIFF=$(( DATE_NOW - DATE_FROM_FILE ))
 
if [ ${DATE_DIFF} -gt 1200 ]; then
   killall firefox
   firefox http://mywebsite.com/
fi

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
That works perfectly... thank you
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.