ksh - AIX: get epoch time/age for a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh - AIX: get epoch time/age for a file?
# 1  
Old 11-26-2008
ksh - AIX: get epoch time/age for a file?

Hi,

(AIX 5.1)
Is there any way to find the epoch timestamp for a file without having to use fancy perl (or similar) scripts? If anyone knows of a way to do this using just ksh commands it would be appreciated.
(It also appears I don't have the stat command available).

Alternatively is there a way to find the age of a file (in seconds or minutes) before $(date) i.e. now.

My aim is to write a script to run as a cron job that will look at the timestamp of some log files we keep. If the timestamp is older than 60 minutes, I want it to echo a message to another file.

Thanks in advance.Smilie
# 2  
Old 11-26-2008
Not that I know. If you don't want to do arithmetics with shell or perl, maybe use "cksum" on those logs and write it to some file and compare it every 60 minutes later.
# 3  
Old 11-26-2008
I know recent versions of AIX have ksh93 installed. Not sure about AIX 5.1 however. If ksh93 is available to you you can easily convert file atime, ctime, etc to seconds from Epoch as show in the following example. After that date arithmetic is easy.
Code:
#!/usr/bin/ksh93
#
# list all files in current directory that are more that 3 days old
#

TMP=file.$$
MIN=$(printf '%(%s)T' "3 days ago")

ls -l > $TMP

while read j1 j2 j3 j4 j5 d1 d2 d3 filename
do
    AGE=$(printf '%(%s)T' "$d1 $d2 $d3")
    # print $AGE
    if (( $AGE < $MIN ))
    then
       print "$d1 $d2 $d3 $filename"
    fi
done < $TMP

rm $TMP

# 4  
Old 11-26-2008
Cheers guys but I've actualy managed to botch my way through this using the find command. Something simple like this is doing everything I need

#!/usr/bin/ksh

LOGDIR=/directory/logs/
DATE=$(date +%Y%m%d)
LOGFILE=mylog.${DATE}

if [[ -z $(find $LOGDIR -name $LOGFILE -mmin -60) ]]
then echo "$LOGFILE has not been modified for 60 minutes" > /tmp/output
else echo "$LOGFILE has normal activity" > /tmp/output
fi

Maybe it's not too pretty but it seems to work - and no need for perl or shell arithmetic.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: time intervals based on epoch time

I have a list of epoch times delimited by "-" as follows: 1335078000 - 1335176700 1335340800 - 1335527400 1335771300 - 1335945600 1336201200 - 1336218000 The corresponding dates are: 20120422 1000 - 20120423 1325 20120425 1100 - 20120427 1450 20120430 1035 - 20120502 1100 ... (3 Replies)
Discussion started by: alex2005
3 Replies

2. AIX

Need to know %age disk busy on AIX

Hi , Following alerts are coming for %busy device on a server Disk Device hdisk5 is 100% busy Please assist how do I analyse this and also how do I check the %age busy for hdisk5. Best regards, Vishal (4 Replies)
Discussion started by: Vishal_dba
4 Replies

3. Shell Programming and Scripting

Converting real time to epoch time

# date +%s -d "Mon Feb 11 02:26:04" 1360567564 # perl -e 'print scalar localtime(1360567564), "\n";' Mon Feb 11 02:26:04 2013 the epoch conversion is working fine. but one of my application needs 13 digit epoch time as input 1359453135154 rather than 10 digit epoch time 1360567564... (3 Replies)
Discussion started by: vivek d r
3 Replies

4. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

5. Shell Programming and Scripting

Calculate age of a file | calculate time difference

Hello, I'm trying to create a shell script (#!/bin/sh) which should tell me the age of a file in minutes... I have a process, which delivers me all 15 minutes a new file and I want to have a monitoring script, which sends me an email, if the present file is older than 20 minutes. To do... (10 Replies)
Discussion started by: worm
10 Replies

6. Shell Programming and Scripting

how to convert date time to epoch time in solaris

Hi, Is there any easy way to convert date time(stored in shell variable ) to epoch time in solaris box? As +%s is working on linux but not on solaris, also -d option is not working. Any suggestion please? (6 Replies)
Discussion started by: anshuman0507
6 Replies

7. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies

8. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

9. UNIX for Advanced & Expert Users

Epoch time

Guys, i have a question... I have 2 sets of data say "a" and "a+1" which has values in epoch time.. Question is... if i were to get the time difference where diff = "a+1" - "a" can i convert it back to real time duration after the subtraction... OR i need to convert em first before i do the... (2 Replies)
Discussion started by: 12yearold
2 Replies

10. Shell Programming and Scripting

Epoch time

Guys, i have a question... I have 2 sets of data say "a" and "a+1" which has values in epoch time.. Question is... if i were to get the time difference where diff = "a+1" - "a" can i convert it back to real time duration after the subtraction... OR i need to convert em first before i do the... (1 Reply)
Discussion started by: 12yearold
1 Replies
Login or Register to Ask a Question