compare dates in shell script

Posted on 2009-02-13
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

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

Could someone help?

Many thanks
Question by:zeraxis_ee
    LVL 23

    Accepted Solution

    1200 is 20 minutes in seconds.
    DATE_NOW=`date +%s`
    DATE_FROM_FILE=`date -d "\`cat lastplaylist\`" +%s`
    if [ ${DATE_DIFF} -gt 1200 ]; then
       killall firefox

    Open in new window


    Author Comment

    That works perfectly... thank you

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    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…
    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…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    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…

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now