• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

Getting a files last modified time in minutes.

I am on a RedHat 7.1 system in the bash shell.

I am very new to .sh scripts and have gotten stuck finding a way to do the following:

I want to query a file from a shell script and get it's last modified time in minutes, rounded.  I am taking this and comparing it against various charts to say.....(example)

If modifed in under the last 5 minutes, do A
If modified between 5 and 10 minutes, do B
If modified greater than 10 minutes ago, do C

The problem, I can't figure out how to get the last modified date in minutes and throw it into a variable.

All I can figure out is how to do a standard -N $file and simply know if it's beeen modified at all since it was last looked at.  This won't do as I need.

Can anyone help?

Thank you,
Frank
0
GrungyApe
Asked:
GrungyApe
  • 2
1 Solution
 
ahoffmannCommented:
ls -l file | gawk '{print substr($8,index($8,":")+1)}'
0
 
ahoffmannCommented:
ls -l file | gawk '{print substr($8,index($8,":")+1)}'
0
 
interiotCommented:
set minsmodded=`perl -le 'print int((time-(stat shift)[9])/60+.5)' filename.txt`


That sets $minsmodded to be the number of minutes since filename.txt has been modified.


0
 
GrungyApeAuthor Commented:
Perfect, exactly as I needed!
Thank you!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now