Sponsored Content
Top Forums Shell Programming and Scripting Trouble calculating difference in number of days Post 302930276 by Ravindra Swan on Thursday 1st of January 2015 12:57:23 PM
Old 01-01-2015
Trouble calculating difference in number of days

Hi all,

I have a requirement to calculate the difference of number of days of time stamp of a file and system date and if the difference is greater than 15 days it should prompt as previous month file otherwise current month file.

Below is the code i used and it is working fine till now. (You can try some date instead of $Publish_Time, it actually carries time stamp of a file)

Code:
Sys_Time=`date |tr -s " "|cut -d" " -f2,3,4|cut -d":" -f1,2`
Sys_Time=`date +%s -d "$Sys_Time"`
Publish_Time=`date +%s -d "$Time_Stamp_cntrl_file"`
Time_Stamp_Diff=`m_eval $Sys_Time-$Publish_Time`
Time_Stamp_Diff=`m_eval $Time_Stamp_Diff/86400`
if [[ $Time_Stamp_Diff -ge 15 ]]; then
echo "file is as of previous month"
else
echo "current month file"
fi

From today since there is change in year, time stamp difference is going negative value and hence even with Dec 1 time stamp it is prompting as current month file.

Any help plz
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

calculating the time difference, when the script was executed and the currenent file

Hi, I has created the shell script in HP_UX 11.23 and using the command, echo $(date +%Y%m%d%H%M%S) > $DIR/alert, placing the time of running the script into a file alert. I want to compare the time in the above file alert with the current time.If difference is more than 5 min, then print the... (7 Replies)
Discussion started by: velocitnitin
7 Replies

2. Shell Programming and Scripting

calculating a number

Hello all :) I need some help; I'm running the sp_spaceused command on various tables and saving the output to a file. So, I have an input file that has 3 rows - each row has 7 columns. I would like to 1) sort the file on the 4th column, 2) take the 4th column in the first row and add 25% to... (2 Replies)
Discussion started by: stonemonolith
2 Replies

3. Shell Programming and Scripting

parsing and calculating difference.

Hi, I have a file with the contents as following Access Time: Thu Nov 6 16:43:45 2008 Modify Time: Thu Nov 6 16:43:45 2008 Change Time: Thu Nov 6 16:43:45 2008 Access Time: Thu Nov 6 16:43:02 2008 Modify Time: Thu Nov 6 16:44:01 2008 Change Time: Thu Nov 6 16:44:01 2008 I need... (3 Replies)
Discussion started by: meetmano143
3 Replies

4. UNIX for Dummies Questions & Answers

Calculating the Number of Rows and Average

Hi All I like to know how can we calculate the number of rows and the average of the values present in the file. I will not know what will be the rowcount, which will be dynamic in nature of the file. eg. 29 33 48 30 28 (6 Replies)
Discussion started by: pk_eee
6 Replies

5. Shell Programming and Scripting

Calculating the difference between dates

Hello! i need to find files lower and bigger that one date i pass, i search in the man find, but i didn't find anything, the only that i find is the parameter -mtime, in this parameter i can pass a number of days, but i need to know the difference between dates, any built-in function for do... (15 Replies)
Discussion started by: claw82
15 Replies

6. Shell Programming and Scripting

Calculating number of records by field

Hi, I have CSV file which looks like below, i want to calulate number of records for each brand say SOLO_UNBEATABLE E and SOLO_UNBEATABLE F combined and record count is say 20 . i want to calculate for each brand, and here only first record will have all data and rest of record for the brand... (2 Replies)
Discussion started by: raghavendra.cse
2 Replies

7. 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

8. UNIX for Advanced & Expert Users

Help with Calculating time difference between many directories in UNIX

A report needs to come some what similar to this No of elements Stream Batch No Load time A B C D A,B,C im able to get quite easily wc -l /usr/local/intranet/areas/prod/output/SRGW_0?/*/MESSAGE_T.dat O/P of above command. A B C ... (1 Reply)
Discussion started by: peckenson
1 Replies

9. Shell Programming and Scripting

Need difference between days

Hi, I am not comfortable with dates and I fail to crack this. I have two strings Date1="Apr 22 23:59:59 2016 GMT" Date2="Dec 1 15:08:40 UTC 2015" I need to find the difference in days between the two dates which in this example is approx 140 days. Is there an easy way to get the... (3 Replies)
Discussion started by: mohtashims
3 Replies

10. Shell Programming and Scripting

Calculating Time difference Between two Rows in Linux

16:45:51 10051 77845 16:45:51 10051 77845 16:46:52 10051 77846 16:46:53 10051 77846 Match the last PID then subtract second line time with first line. Please help me with any command or script. working in media company on a project OS: RHEl7 tried command: awk 'function... (2 Replies)
Discussion started by: vivekn
2 Replies
uucleanup(1M)															     uucleanup(1M)

NAME
uucleanup - uucp spool directory clean-up SYNOPSIS
time] time] time] time] string] time] system] debug_level] DESCRIPTION
The commands, including are targeted for removal from HP-UX; see the below. scans the spool directories for old files and takes appropriate action to remove them. Depending on the options selected, performs the following: o Informs the requestor of send and/or receive requests for systems that cannot be reached. o Returns mail that cannot be delivered to the sender. o Removes all other files. In addition, warns users of requestors who have been waiting for a given number of days (the default is 1 day). Note that unless time is specifically set, the default time values for the following options are used. Options recognizes the following options: Any files greater or equal to time days old are removed with appropriate information to the requestor. The default time is 7 days. Any files greater or equal to time days old are removed. An attempt is made to deliver mail messages and execute news when appropriate. The default time is 7 days. Any files equal to time cause a message to be mailed to the requestor warning about the delay in contacting the remote. The message includes the JOBID, and in the case of mail, the mail message. The administrator can include a message line telling who to call to correct the problem (see the option). The default time is 1 day. Any files greater than or equal to time days old are removed. The files are probably not present (if they were, the could be executed). But, if files are present, they are taken care of by processing. The default time is 2 days. This string is included in the warning message generated by the option. The default string is Other files whose age is more than time days are deleted. The default time is 2 days. Clean-up the spool directory for system only. The default is to clean-up all spool directories. The debug level is a single digit between 0 and 9. The higher the numbers, the more detailed the debugging information returned. This program is typically started by the script which should be started by (see cron(1M)). WARNINGS
Use of commands, including is discouraged because they are targeted for removal from HP-UX. Use ftp(1) or rcp(1) instead. FILES
spool directory SEE ALSO
cron(1M), uucp(1), uux(1), uuclean(1M). Tim O'Reilly and Grace Todino, O'Reilly & Associates, Inc. USA. Grace Todino and Dale Dougherty, O'Reilly & Associates, Inc. USA. TO BE OBSOLETED uucleanup(1M)
All times are GMT -4. The time now is 01:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy