Date not returning
Hi There
I am trying to do the difference of two file dates, however when I do the some the return is blank. Any help would be greatly appreciated. Code:
current_time=`date +%s` Quote:
|
try this:
Quote:
|
Doing math like that is your problem.
Try something like, and note that you need the white spaces around the minus sign: Code:
diff_sec=`expr $current_time - $last_login_of_tim` |
Quote:
Great thank you :) What was I doing wrong? I assume this is showing in seconds how would I show in minutes? |
Your syntax for Arithmetic Expansion is incorrect. I suspect you are assuming that `command` == $(command) is equivalent in similar cases.
However, while Command Substitution may be implemented with `command` or $(command), Arithmetic Expansion is only implemented by doing $((expression)) Using `command` is poor form however. It's hard to read and cannot be nested. |
also:
Quote:
|
An important point to observe here is that you did not know where the error resided in your script.
If you add a "set -xv" line near the start of the script, it would have enabled verbose output and informed you that there was a problem with your mathematical attempt. From there any of the offered solutions to fix that line are applicable. |
Some date math in http://www.linuxquestions.org/questi...rt-4175544200/ may help.
|
Hi Guys
Thanks for all your help on this much appreciated :) Usually for time you take the first 10 characters of a files name, what if the file I am looking at has the date within it? File 'Wynyard_MTP_Primary-btstats-2017-03-29-10:34:50.xml' This is the file I want to do the same the difference between the dates but as it has the date already in it won't I need to do something different? Cheers Alex |
Quote:
That can be done with grep and regular expressions. Character Classes and Bracket Expressions may help you here (look in man grep) For example, to match 4 digits, followed by a dash, then 2 digits I would do something like: Code:
$ echo 'hello 5555-33 world' | grep -oE [[:digit:]]{4}-[[:digit:]]{2} Code:
-E, --extended-regexp |
All times are GMT -5. The time now is 04:03 PM. |