Add a line of test and removing it 10 mins later

Does anyone know how to add a line of text to a file and then remove the next time the script is executed, but only if ten minues has gone since the line was added?

I guess adding a timestamp at the and of each line could work, but how..?

Thanks in advance...

Vegard

Comments

  • : Does anyone know how to add a line of text to a file and then remove the next time the script is executed, but only if ten minues has gone since the line was added?
    :
    : I guess adding a timestamp at the and of each line could work, but how..?
    :
    : Thanks in advance...
    :
    : Vegard
    :


    You can open the file as this:

    if (!(open("LOG", ">>file.log")))
    {
    die("ERROR: Could not open ftp.log.");
    }

    with file.log being any file name
    and LOG being the file handler

    then you can use this subroutine that i had for getting the time:

    sub Get_Time
    {
    @timelist = localtime(time);
    $timelist[5] -= 100;
    $timelist[4] += 1;

    for ($i=0; $i<6; $i++)
    {
    if($timelist[$i]<10)
    {
    $timelist[$i] = '0'.$timelist[$i];
    }
    }

    print LOG ($timelist[4]);
    print LOG ("/$timelist[3]/");
    print LOG ($timelist[5]);
    print LOG (" $timelist[2]:$timelist[1]:$timelist[0]");
    }

    // mm/dd/yy hh:mm:ss

    Then open the file read the time stamp and delete or dont delete.
    hope this helps, and hope its right.

    Dave



  • : : Does anyone know how to add a line of text to a file and then remove the next time the script is executed, but only if ten minues has gone since the line was added?
    : :
    : : I guess adding a timestamp at the and of each line could work, but how..?
    : :
    : : Thanks in advance...
    : :
    : : Vegard
    : :
    :
    :
    : You can open the file as this:
    :
    : if (!(open("LOG", ">>file.log")))
    : {
    : die("ERROR: Could not open file.log.");
    : }
    :
    : with file.log being any file name
    : and LOG being the file handler
    :
    : then you can use this subroutine that i had for getting the time:
    :
    : sub Get_Time
    : {
    : @timelist = localtime(time);
    : $timelist[5] -= 100;
    : $timelist[4] += 1;
    :
    : for ($i=0; $i<6; $i++)
    : {
    : if($timelist[$i]<10)
    : {
    : $timelist[$i] = '0'.$timelist[$i];
    : }
    : }
    :
    : print LOG ($timelist[4]);
    : print LOG ("/$timelist[3]/");
    : print LOG ($timelist[5]);
    : print LOG (" $timelist[2]:$timelist[1]:$timelist[0]");
    : }
    :
    : // mm/dd/yy hh:mm:ss
    :
    : Then open the file read the time stamp and delete or dont delete.
    : hope this helps, and hope its right.
    :
    : Dave
    :
    :
    :


  • Is there any particular place that the line to add would go?
    What is the purpose of the line, other than just indicating
    the time that the file was last modified?

    If you're only wanting to check files that have been modified
    more than 10 minutes ago, you could use stat to find the last
    modify time, and compare it with the current time.

    Something like:
    [code]
    #!/usr/bin/perl -w
    # accesstime.pl - TLD - Aug 10, 2001
    use strict;

    my($timeDifference);

    # for each time, we stat[9] (last modify time in seconds since epoch), then
    # subtract that from the current time (seconds since epoch), and divide by
    # 60 to get the number of minutes

    for("/etc/passwd","./accesstime.pl") {
    $timeDifference=int((time-(stat($_))[9])/60);
    print "$_ was last modified ", $timeDifference, " minutes ago.
    ";
    }
    exit;
    [/code]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion