LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-05-2015, 12:56 AM   #1
murali2489
LQ Newbie
 
Registered: Jan 2015
Posts: 14

Rep: Reputation: Disabled
Script to find the file creation time is more than ten minutes


Hi All,

Im trying to create a script which checks the creation time of a file and if it is more than ten minutes, send out an alert.

For ex : Creation date of file is 10:30 AM
current time is 10:45 AM

Then send an alert/ message.

This is the script i wrote below :

Code:
#!/bin/ksh

filename="/apps/log/file.txt"

if [ -f "${filename}" ]
then
        createTime=`ls -lad "${filename}" | awk '{print $8}'`
        echo "$createTime"
        currentTime=`date '+%M'`
        echo "$currentTime"
        DIFF=$(( $currentTime - $createTime )) 
        echo "$DIFF"

else

        exit 1

fi
I am getting syntax error on the subraction when i try to run this script . I can understand that creation time and current time is in different format thats y this error throws, but i dont know how to rectify it .

I need to find out if the file creation time is more than ten minutes.

Please help me in achieving this output.
 
Old 03-05-2015, 01:08 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

you seem to be working with the change time not the creation time (which is generally not available).
If you are happy with the change time you can use find. For example to find files in the current directory that were modified within the last ten minutes you can use:
Code:
find . -cmin -10
HTH,

Evo2.
 
1 members found this post helpful.
Old 03-05-2015, 01:10 AM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,880
Blog Entries: 1

Rep: Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998
You would probably be far ahead using find with use of -newer option and a suitably touched reference.

See man find for -newer option behavior.

++++
Or what evo2 said, -cmin looks even easier...

Last edited by astrogeek; 03-05-2015 at 01:12 AM.
 
1 members found this post helpful.
Old 03-05-2015, 02:05 AM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,
Quote:
Originally Posted by astrogeek View Post
Or what evo2 said, -cmin looks even easier...
Yeah but it looks like I misread the question, so the -cmin command would actually be
Code:
find . -cmin +10
Evo2.
 
2 members found this post helpful.
Old 03-05-2015, 04:01 AM   #5
murali2489
LQ Newbie
 
Registered: Jan 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
Hi evo2, astrogeek ...

Thanks Verymuch !!!!

I understand ...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
command to find the folder creation time in linux forumbala88 Linux - Server 2 04-02-2013 09:56 AM
Script - Find time between entries in log file blsimpson Linux - Newbie 16 07-24-2012 07:03 PM
[SOLVED] Find folder creation time kenneho Linux - Newbie 2 08-24-2009 08:56 AM
how to find time of file creation of a given file??? raklo Linux - General 4 08-13-2007 06:28 AM
script to find out time taken to transfer a file aeby Linux - Networking 1 05-09-2007 06:29 AM


All times are GMT -5. The time now is 12:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration