Web Analytics Made Easy -
StatCounter Cron job 2 things - CodingForum

Announcement

Collapse
No announcement yet.

Cron job 2 things

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cron job 2 things

    #1. I have a cron job that runs at midnight eastern time every day. In this cron I want to have it check for users who haven't logged in for 90 days and delete them. I am not good at time/date difference at all.

    #2. My cron runs on my server fine and is automatic. But if I do a manual link to it like www.mysite.com/mycron.php it runs it. So if anyone finds out the link to it, it can mess everything up badly. How can I block a manual url to it?
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #2
    1. This will depend on how you're storing the timestamps. If its an actual unix timestamp, all you need to do is subtract the last logged in time from now and check how many days it is (can be done in SQL).

    2. Put the cron script above the public_html directory. Problem solved, cron will not have a problem with finding it since you generally give a full path to a cron.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

    Comment


    • #3
      #1. It uses DATETIME and the format is this 0000-00-00 00:00:00

      #2. Thank you! I shall change it
      Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

      Comment


      • #4
        Something along these lines should get you the results you're looking for. What's selected, the name of the table and the database connection need to be updated for your situation of course.

        PHP Code:
        mysql_query("SELECT `id` FROM `tablename` WHERE DATE_SUB(`datefield`,INTERVAL 90 DAY) <= CURRENT_DATE,yourdb) or die(mysql_error()); 
        The following snippet is something I use that changes order status when a date field is within 3 days of the current date which may give you an idea of how you could use it.

        PHP Code:
        $pendQ   mysql_query("SELECT `id` FROM `mytable` WHERE DATE_SUB(`reqdate`,INTERVAL 3 DAY) <= CURRENT_DATE and `status` = 'P' and `reqdate` != ''",COMPANYDB) or die(mysql_error());
        if (
        mysql_num_rows($pendQ) == 0) {
            exit;  
        # nothing to do today so just go away quietly
        };
        $pendRow mysql_fetch_assoc($pendQ);
        do {
            
        mysql_query("UPDATE `mytable` SET `status` = 'N' WHERE `id` = '" $pendRow['id'] . "'",COMPANYDB) or die(mysql_error());
            
        LogIt($pendRow['id'] . ' status changed to New');
        } while (
        $pendRow mysql_fetch_assoc($pendQ)); 
        Dave .... HostMonster for all of your hosting needs

        Comment


        • #5
          Hmm confusing, I will need to read over this a few times to try to understand it. Because I don't want to have it run and delete half the database and mess everything up, so need to make sure its correct the first time.
          Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

          Comment


          • #6
            FWIW, when I'm working on something with the potential for doing the wrong thing I work with it locally and have something like what I posted show me the results and the SQL that would be executed rather than having it actually do something. Even after that I grab a backup of the table(s) that are going to be affected just before I turn it loose just in case.
            Dave .... HostMonster for all of your hosting needs

            Comment

            Working...
            X