It is currently Fri, 15 Oct 2021 20:04:52 GMT



 
Author Message
 Testing and Grabbing a files filedate?
Can anyone tell me how to do the following, or where to find how to do the
following?

Look at a file, and grab it's filedate and compare it to the date current date
to see if the file has been altered since a certain other date.

An example of what I want to do is to check if new mail has been recieved`
since last login.

Since the mail file in /usr/spool/mail is updated everytime mail is received
I need to grab that filedate and compare it to the last login date (I don't
know where that is on SunOS).  If it is newer than the last login, then a
prompt should state that I have new mail not previously read.

This is only an example of what I want to do, but the principle is always the
same.

Thanks,
Christopher Walton
cmw1...@tamsun.tamu.edu



 Mon, 07 Mar 1994 00:08:06 GMT   
 Testing and Grabbing a files filedate?
From the keyboard of cmw1...@tamsun.TAMU.EDU (Christopher Walton):
:Can anyone tell me how to do the following, or where to find how to do the
:following?
:
:Look at a file, and grab it's filedate and compare it to the date current date
:to see if the file has been altered since a certain other date.
:
:An example of what I want to do is to check if new mail has been recieved`
:since last login.
:
:Since the mail file in /usr/spool/mail is updated everytime mail is received
:I need to grab that filedate and compare it to the last login date (I don't
:know where that is on SunOS).  If it is newer than the last login, then a
:prompt should state that I have new mail not previously read.
:
:This is only an example of what I want to do, but the principle is always the
:same.

If you're using a shell, look at find's -newer and -older operators;
they make well work for you.  

If your program is in perl, you'll have considerably more flexibility:
check out the -M, -A, and -C operators, which return respectively the age
in days of the mtime, atime, and ctime of the file.  Or you can use stat()
or lstat() to pull out all those fields in real UNIX epoch seconds.  For
example:

    if (-M $file1 > -M $file2) {
        # do something
    }

    foreach $file (@filelist) {
        $mtime{$file} = (stat($file))[9];  # mtime is 9th elt
    }

--tom



 Mon, 07 Mar 1994 00:26:16 GMT   
 Testing and Grabbing a files filedate?

Why bring out the cannon for a pistol sized problem?  ls has always been able
to sort based on time.  The following comes from my .login file:

    set motd=(`ls -t /etc/motd ~/.hushlogin`)
    cat $motd[1]
    if ( $motd[1] == ~/.hushlogin ) touch $motd[1]

I maintain a .hushlogin file in my home directory.  This keeps login from
spouting the motd every time I log in.  I then compare the dates on the
.hushlogin file and the motd file and cat the newer (.hushlogin is a zero
length file).  Yes, I could prevent the cat if I know that the size is zero,
or if I know that the name is .hushlogin, but the test would cost
about as much as the cat.  Next I touch the .hushlogin file marking
the fact that I just saw the motd.  I wish I didn't have to do a test
here, but I don't like trying to touch /etc/motd by accident.

I have seen other approaches in which .hushlogin is a makefile. In this
case, you do a
        make -f ~/.hushlogin
in which the default rule cats /etc/motd if it is newer than .hushlogin,
then touches .hushlogin.  This will work also, but ls loads in about
1/10 the time that make does.

You can easily modify this to tell you that you have new mail, tell you
when somebody changes the password file, etc.  If somebody has an even
faster way, I would love to see it.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-%-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Roger Knobbe                                    Locus Computing Corporation
kno...@locus.com                            9800 La Cienega
These are my opinions.  I doubt they            Inglewood, CA   90301-4440



 Mon, 07 Mar 1994 03:51:20 GMT   
 Testing and Grabbing a files filedate?
From the keyboard of kno...@locus.com (Roger Knobbe):
:>:Can anyone tell me how to do the following, or where to find how to do the
:>:following?
:>:
:>:Look at a file, and grab it's filedate and compare it to the date current date

:>If your program is in perl, you'll have considerably more flexibility:

:Why bring out the cannon for a pistol sized problem?  ls has always been able
:to sort based on time.  

Because I didn't know the kind of application he had in mind.  Certainly
if you just want to look compare a file's mtime with the current date, as
was requested ls seems a funny way to go about it.  For some applications,
of course, ls is just fine.

But the spec sure sounded more like they wanted something like this:

    perl -e 'printf "Last touched .cshrc: %.2f days ago\n", -M ".cshrc"'

--tom



 Mon, 07 Mar 1994 10:05:25 GMT   
 Testing and Grabbing a files filedate?

Hi, here is a simple script that can do your work:

#! /bin/sh
MAILDIR=/usr/spool/mail
MAILFILE=$MAILDIR/`logname`

box_changed()
{
# This function returns the length of the mailbox
        if [ ! -f $MAILFILE ]; then # Empty box
                return 0
        fi
        wc -l  $MAILFILE | awk '{print $1}'

box_date_changed()
{
# This function returns the date of the mailbox
        if [ ! -f $MAILFILE ]; then # Empty box
                return 0
        fi
        ls -lo $MAILFILE | awk '{print $7}'

        OLD_DATE=`box_date_changed` # Get old modification time

        # box_changed() can also determine if a new mail has arrived
        # It does this by measuring the current length of the mailbox,
        # and comparing it to the old box length
        #
        # Do something here
        #
        # ...
        # ...
        #

        NEW_DATE=`box_date_changed` # Did box date change?
        if [ "$OLD_DATE" != "$NEW_DATE" ]; then
                   OLD_DATE="$NEW_DATE"
                   # Box date changed, see who the sender is
                   FROM=`from | tail -1 | cut -d" " -f2`
                   echo "New mail has arrived from $FROM"
        fi

su...@xantos.uio.no (Suleyman Kondakci)



 Mon, 07 Mar 1994 17:56:37 GMT   
 Testing and Grabbing a files filedate?
From the keyboard of su...@xantos.uio.no (Suleyman Kondakci):

:>Can anyone tell me how to do the following, or where to find how to do the
:>following?
:
:>Look at a file, and grab it's filedate and compare it to the date current date
:>to see if the file has been altered since a certain other date.
:
:>An example of what I want to do is to check if new mail has been recieved`
:>since last login.
:
:Hi, here is a simple script that can do your work:

Well, notice you can only check string == and !=, not timewise < or >.

If you have a lastlog file on your system (and I think most do) you
index into that by uid to pull out the date of the last login, then
compare that with the mtime of the spool file.  This is easy in perl,
although I suspect it could be done in a shell script using the Cnews
getdate program.  Not everyone has getdate, but then not everyone has
cut or a shell with functions, and `logname` I've never even heard of.

Still, I think you could code it with just getdate and last and sed
in a sh script if you go in for that kind of thing.  I don't.

Perl snippet follows.

--tom

#!/usr/bin/perl
$LASTLOG =  '/usr/adm/lastlog';
$USER = $ENV{'USER'} || $ENV{'LOGNAME'} || (getpwuid($>))[0];

($msize,$mtime) = (stat("/usr/spool/mail/$USER"))[7,9];
exit unless $msize;

$fmt = 'l A8 A16';  # should require 'utmp.ph' for true portability
$size = length(pack($fmt, ())); # get record size

open  LASTLOG                           || die "can't open $LASTLOG: $!";
seek (LASTLOG, $> * $size, 0)                || die "can't seek $LASTLOG: $!";
read (LASTLOG, $record, $size) == $size || die "can't read $LASTLOG: $!";

($lasttime) = unpack($fmt, $record);
if ($mtime > $lasttime) {
    print "mailbox (size $msize) modified since last login\n";



 Mon, 07 Mar 1994 22:12:55 GMT   
 
   [ 6 post ] 

Similar Threads

1. test test test test test test test

2. Grabbing file from file descriptors

3. Wrong filedates with sambaclient

4. Backing up Fire by filedate ??

5. Obtaining UNIX filedate in C++

6. pkgmk grabs wrong file

7. How to grab the post-processed fvwmsrc.m4 file

8. what does each cvsup example file grab?

9. How to grab a token from a line in file then compute all of these tokens

10. Grabbing a small piece from a huge file


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software