![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Get date and time for past 1 hour from current date | spch2o | Shell Programming and Scripting | 5 | 10 Hours Ago 01:32 AM |
| Perl: Extracting date from file name and comparing with current date | MKNENI | Shell Programming and Scripting | 4 | 03-26-2008 12:01 PM |
| calculate the date of next satureday of current date. | rinku | Shell Programming and Scripting | 1 | 02-27-2008 04:40 PM |
| check the current date file in directory | pallvi | SUN Solaris | 2 | 01-04-2008 01:57 PM |
| how to give current date in file name? | simurg11 | UNIX for Dummies Questions & Answers | 3 | 05-10-2005 06:09 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
File date vs Current date
I am a newbie in shell scripting, hope you can advice how can I compare the date/time of file extracted from 'll' and current system date/time.
I have done the following: ll -rt > $FILE_AGE_LOG FILE_DATETIME=`more $FILE_AGE_LOG | head -02 | cut -c 45-57` It returns 'May 4 19:11'. If I want to put in a condition to check if the file is more than 15 minutes old, something like the following. if [ $FILE_DATETIME < (`date`-15) ] Please kindly advice how can I do that? Thanks. |
| Forum Sponsor | ||
|
|
|
|||
|
try something like this:
Code:
#!/bin/ksh
# tdiff.sh
tdiff()
{
perl -e '
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat("$ARGV[0]");
$difference = time - $mtime;
print $difference;
' "$1"
}
secs=$(tdiff "$1")
minutes=$secs/60
if [[ $minutes -le 15 ]] ; then
echo "$1 is 15 minutes old or less"
else
echo "$1 is older than 15 minutes"
fi
|
|
|||
|
Following on with Shell Life
You could after touching the 'timestamp' file, do
'ls -ltr' and see what files are listed after the datestamp file. Note that the granularity of the list may only be to the nearest minute. |