Sponsored Content
Top Forums Shell Programming and Scripting How to get timestamp of file into ksh script Post 302310523 by devtakh on Saturday 25th of April 2009 10:27:07 AM
Old 04-25-2009
Quote:
Originally Posted by sniper57
Thanks for the replies.

Unfortunately I don't have the stat command available in my AIX envt.

The timestamp needs to be in this format : 20090425000000
so yyyymmddhhmmss

Maybe it would be easier to just write/append the timestamp to a file and read the last entry from that? I just feel there has to be a neater way of doing this!

How do I get the timestamp in the format I want from something like :
ls -l $FILE | awk '{sub(/:/,"",$8);print $8}' ?

what you can possibly do is ..in you ldap script, before it completes successfully, touch the logfile so tht the file will have the latest timestamp (you can write sme msg to the logfile)

then use

lastrun=`ls -l --time-style='full-iso' add | awk '{s=$6$7;gsub(/[:-]/,"",s);print substr(s,1,14)}' `
now=$(echo `date +"%Y%m%d%H%M%S"`)

then compare the above two variable

if [[ $now < $lastrun ]]; then
echo "Greater"
else
echo "Lower"
fi


cheers,
Devaraj Takhellambam
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I want to get timestamp from a text file using ksh

for example : 07:25 Thanks (1 Reply)
Discussion started by: vinna
1 Replies

2. AIX

timestamp in .sh_history using ksh shell

Hello Everyone: Does anyone know how I will setup my account to put timestamp in my .sh_history? I do not hold the root account. I am using AIX 5 and ksh shell. I tried every solution I can find in the internet but nothing seems to work OR I am just applying those in the wrong way. Anyone knows... (4 Replies)
Discussion started by: Orbix
4 Replies

3. UNIX for Advanced & Expert Users

how to get timestamp of a file in a perl script

I have seen this posting here: perl -e '@d=localtime ((stat(shift))); printf "%02d-%02d-%04d %02d:%02d:%02d\n", $d,$d+1,$d+1900,$d,$d,$d' file1.txt I need to use it inside a perl script. Can anybody please help me out. (5 Replies)
Discussion started by: biswajeet.beher
5 Replies

4. Shell Programming and Scripting

Timestamp to date conversion in ksh

Hi, I have a file containing timestamp( Example given below). How can i get date(mmd-dd-yyyy) from it? ($> cat file1.txt 2008-11-24 05:17:00.7043) Thanks, Sri (2 Replies)
Discussion started by: srilaxmi
2 Replies

5. UNIX for Advanced & Expert Users

In ksh find out the timestamp of current date?

Normally we can use %s to find out the time in second since 1970. But in my ksh, this format option is not available. Example- date +%s 1268103151 above script command won't work in ksh. Can you guys provide its equivalent ? (3 Replies)
Discussion started by: boy18nj
3 Replies

6. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

7. Shell Programming and Scripting

Getting a relative timestamp from timestamp stored in a file

Hi, I've a file in the following format 1999-APR-8 17:31:06 1500 3 45 1999-APR-8 17:31:15 1500 3 45 1999-APR-8 17:31:25 1500 3 45 1999-APR-8 17:31:30 1500 3 45 1999-APR-8 17:31:55 1500 3 45 1999-APR-8 17:32:06 1500 3 ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

8. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

9. Shell Programming and Scripting

How to get the timestamp for file using shell script

I am writing a script to move the executable from one node to another and take the backup of the existing one. For that I want to fetch the timestamp of file using shell script. Could anyone help? (2 Replies)
Discussion started by: gagankinra
2 Replies

10. Shell Programming and Scripting

Bash Script Closest Timestamp (LOG FILE)

Hi All, I need something where I could take the date from FILE1 and in this case the date is Thu Sep 10 13:48:42 EDT 2015 and I need it to match the closest PREVIOUS date in the log file FILE2 this means in this specific case it would be Thu Sep 10 2015 13:35:28. I only need the closest... (3 Replies)
Discussion started by: roberto999
3 Replies
GMDATE(3)								 1								 GMDATE(3)

gmdate - Format a GMT/UTC date/time

SYNOPSIS
string gmdate (string $format, [int $timestamp = time()]) DESCRIPTION
Identical to the date(3) function except that the time returned is Greenwich Mean Time (GMT). PARAMETERS
o $format - The format of the outputted date string. See the formatting options for the date(3) function. o $timestamp - The optional $timestamp parameter is an integer Unix timestamp that defaults to the current local time if a $timestamp is not given. In other words, it defaults to the value of time(3). RETURN VALUES
Returns a formatted date string. If a non-numeric value is used for $timestamp, FALSE is returned and an E_WARNING level error is emitted. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.1.0 | | | | | | | The valid range of a timestamp is typically from | | | Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 | | | 03:14:07 GMT. (These are the dates that corre- | | | spond to the minimum and maximum values for a | | | 32-bit signed integer). However, before PHP 5.1.0 | | | this range was limited from 01-01-1970 to | | | 19-01-2038 on some systems (e.g. Windows). | | | | | 5.1.1 | | | | | | | There are useful constants of standard date/time | | | formats that can be used to specify the $format | | | parameter. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 gmdate(3) example When run in Finland (GMT +0200), the first line below prints "Jan 01 1998 00:00:00", while the second prints "Dec 31 1997 22:00:00". <?php echo date("M d Y H:i:s", mktime(0, 0, 0, 1, 1, 1998)); echo gmdate("M d Y H:i:s", mktime(0, 0, 0, 1, 1, 1998)); ?> SEE ALSO
date(3), mktime(3), gmmktime(3), strftime(3). PHP Documentation Group GMDATE(3)
All times are GMT -4. The time now is 07:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy