lnl has asked for the wisdom of the Perl Monks concerning the following question:

How can make my CGI script 'look' like a cron job has run?

In the configuration, users will designate a time each day when everyone is logged OUT of their IN/OUT board. Whenever the script is run to check the board, it should look to see whether it is time (or past time) to log everyone out and whether it has already happened. I thought maybe I could somehow use a semaphore file and/or 'stat' the file.

Does anyone have a code snippet that does this?

The crontab alternatives I have found try too hard to act like real cron jobs, and I want to keep this very simple and transparent for the users.

Thanks,

--lnl

Replies are listed 'Best First'.
Re: Simple crontab alternative
by fmerges (Chaplain) on Jul 16, 2005 at 18:33 UTC

    Hi,

    Can you be more explicit, because I don't really understand what's the purpose, what you want...

    Regards,

    |fire| at irc.freenode.net

    I like merlyn's disclaimer

Re: Simple crontab alternative
by Cody Pendant (Prior) on Jul 17, 2005 at 07:51 UTC
    Surely the logic is very simple?

    "If the time is equal to or greater than LOGOUT_TIME, and ALREADY_DONE(TODAYS_DATE) is false, then DO_LOGOUT_SCRIPT and set ALREADY_DONE(TODAYS_DATE) to true."

    How you set and store the time and where you save the value for "already done" are dependent on your system.



    ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
    =~y~b-v~a-z~s; print
      Thanks! That is a start.

      I was hoping to hear how others may have employed a semaphore file and dealt with possible reliability issues...
      like, what if the semaphore file somehow got deleted.

      --lnl

Re: Simple crontab alternative
by lnl (Pilgrim) on Jul 17, 2005 at 17:34 UTC
    UPDATE:

    OK... here is what I came up with:
    If the time since the semaphore file was created is greater than the time since the 'desired logout time', log everyone out and recreate the semaphore file.

    However, if the semaphore file does not exist, for whatever reason, create it, but don't log everyone out. This will delay the logout until the next 'desired logout time'.

    Suggestions are still welcome...

    --lnl

Re: Simple crontab alternative
by TedPride (Priest) on Jul 18, 2005 at 07:00 UTC
    Assuming you use cookies for authentication, you can store the next logout timestamp in a cookie and then log the user out if that time has been passed. To make sure that the cookie contents haven't been spoofed, add the logout timestamp to your hash input, so instead of hashing user+sitekey, you hash user+logout+sitekey.

    Really very simple to do, and no cron spoofing needed.