Sponsored Content
Top Forums Shell Programming and Scripting How to find the create time of a file if current date is in next month Post 302317084 by vidyadhar85 on Monday 18th of May 2009 04:19:56 AM
Old 05-18-2009
try this remove the unnecessary part Smilie
Code:
function time_diff
{
awk -v start_time=$1 -v end_time=$2 'BEGIN{
if ( start_time !~ /^[0-9]/ || end_time !~ /^[0-9]/ )
usage(start_time,end_time)
split(start_time,T2,":")
split(end_time,T1,":")
start_seconds=T1[1]*60*60+T1[2]*60+T1[3]
end_seconds=T2[1]*60*60+T2[2]*60+T2[3]
if ( start_seconds > 86401 || end_seconds > 86401)
usage("out_off_range","")
elapsed_seconds=start_seconds-end_seconds
if( elapsed_seconds < 0 )
{elapsed_seconds=elapsed_seconds*-1
calculate(end_time,start_time,elapsed_seconds)}
else
calculate(start_time,end_time,elapsed_seconds)}
function calculate(start_time,end_time,elapsed_seconds){
HH=elapsed_seconds / 3600
MM=(elapsed_seconds % 3600) / 60
SS=elapsed_seconds % 60
printf  "TIME DIFFERENCE BETWEEN "start_time"(START TIME)-"end_time"(END TIME)--> +%02d:%02d:%02d\n",HH,MM,SS }
function usage(start_time,end_time){
if( start_time=="out_off_range" )
printf "TIME OUT OFF RANGE\n"
else
printf "INVALID TIME FORMAT "start_time" "end_time"\n"
printf "USAGE : time_diff.sh <HH:MM[:SS]> <HH:MM[:SS]>\n"
exit}'
}
time_file=`ls -l abc.txt|awk '{print $8}'`
time_current=`date +%T`
time_diff $time_file $time_current

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I create a file with current time - 60 minutes

I'm using k-shell in unix and I want to create a file with the current system time - 60 minutes. I know I can use touch to create the file, but I'm having trouble specifying how tell it to use the current time less 60 minutes. Any ideas??? (4 Replies)
Discussion started by: DaveyTN
4 Replies

2. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies

3. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

4. Shell Programming and Scripting

How to extract log data based on current date and month ?

Hi Gurus, I'm using HP-UX B.11.23 operating system. I've been trying to extract this log info based on the current date and month, but was having some issues as the date column which on the 4th column has a comma and the 5th column has a dot tied to it. Here is the output from my shut... (5 Replies)
Discussion started by: superHonda123
5 Replies

5. Shell Programming and Scripting

current date - one month in AIX

Hi, i unable to get the last month date in AIX. current date - one month Based on the forums tried but did not find the relevent information. Any help grealy appriciated. Thanks Suri. (3 Replies)
Discussion started by: onesuri
3 Replies

6. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

I have requirment to get last date of previous month and the first date of previous 4th month: Example: Current date: 20130320 (yyyymmdd) Last date of previous month: 20130228 (yyyymmdd) First date of previous 4th month: 20121101 (yyyymmdd) In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies

7. Shell Programming and Scripting

How do i find a file with the current time stamp in it??

I want to find a file using find or any utility having the current date time stamp..... I have an alternate way to do that.... but that is too way out of logic... so looking out something with find itself (5 Replies)
Discussion started by: nikhil jain
5 Replies

8. AIX

AIX - Get next month from current date

As said in object, how can i obtain that? In linux i use date -d "1 month" +"%m%Y". Thanks i advance. (8 Replies)
Discussion started by: fabfisc
8 Replies

9. Homework & Coursework Questions

How to minus 2 month from current date?

I am running a script in ksh to get the 2 months back date from system date.The below code is giving correct date output from putty command prompt.But while running the script is .ksh file it is giving the error below.Please suggest. ; d=a; y=a m-=num while(m < 1) {m+=12; y--}... (1 Reply)
Discussion started by: hini
1 Replies

10. UNIX for Beginners Questions & Answers

How to get first & last day of a month from current date?

Hi, I need the first & last day of a month from any given date. For better understanding, if i need to back-fill data for date 07/20/2019 i.e July 20 2019, i need the first & last day has 07/01/2019 - 07/31/2019. FYI: I'm using GIT BASH terminal. sample code: export DT=$(date --date='6 days... (2 Replies)
Discussion started by: Rocky975583
2 Replies
time_lock_es(3) 					     Library Functions Manual						   time_lock_es(3)

NAME
time_lock_es - Check time-of-day locking (Enhanced Security) LIBRARY
Security Library (libsecurity.so) SYNOPSIS
#include <sys/types.h> #include <sys/security.h> #include <prot.h> int time_lock_es ( struct es_passwd *prpwd ); PARAMETERS
Specifies a protected password entry structure. DESCRIPTION
The time_lock_es() function performs time-of-day lock checking for the current date and time against the time-of-day specification in the fd_tod string of the prpwd parameter. The function returns 1 if the time lock is on and 0 if there is no lock. The fd_tod specification is like that found in the UUCP Systems file. The specification is a comma-separated list of entries. If the cur- rent time matches an entry in the specification, the time lock is not on. The entries are scanned until a match is found. If no match can be found, the time lock is on. Each entry appears as follows: <day><start_time-end_time> The day is one of the following: Matches any day of the week. Matches Monday through Friday. Sunday Monday Tuesday Wednesday Thursday Friday Saturday The times are military time, for example, 9:15 am is 0915, 6:00 pm is 1800, and 12:42 am is 0042. When start_time is less than end_time, the range of times contains valid times in which to log in that day. When the times are equal or there is only one time (including no time at all), the entire day is valid. When start_time is later than end_time, times outside the range are valid. For instance, if start_time is 04:15 and end_time is 02:00, then any time that falls outside the range of 02:00 to 04:15 is a valid time. NOTES
Programs using this function must be compiled with -lsecurity. In order to quickstart a program, the program must be linked as follows: -lsecurity -ldb -laud -lm See the shared library discussion in the Programmer's Guide for more information about using the quickstarting feature. delim off time_lock_es(3)
All times are GMT -4. The time now is 09:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy