Results 1 to 17 of 17
  1. #1
    Join Date
    Dec 2000
    Posts
    532

    Need simple ASP code for cronjob

    In order to keep my website "fresh" I would like to run an ASP script with scheduled tasks. I am not an asp programmer but wonder if someone could give me a few lines of code to do the following:

    I want to run a script that will select a different include file every 24 hours. For example:

    <!-- #include file="a.inc" -->
    <!-- #include file="b.inc" -->
    <!-- #include file="c.inc" -->
    <!-- #include file="d.inc" -->
    <!-- #include file="e.inc" -->

    Each include file would be slightly different to give freshness to the homepage.

    Thanks,

    Ron

  2. #2
    Join Date
    Jan 2004
    Posts
    406
    Instead of using a Scheduled Task you may be able to do the following, but it really depends on the content of the include files.
    Code:
    <%
    Select Case Day(Date()) ' This will return the day of the week as a number
         Case 1
              Server.Execute "a.asp"
         Case 2
              Server.Execute "b.asp"
         Case 3
              Server.Execute "c.asp"
         Case 4
              Server.Execute "d.asp"
         Case 5
              Server.Execute "e.asp"
         Case 6
              Server.Execute "f.asp"
         Case 7
              Server.Execute "g.asp"
    End Select
    %>
    Also note that the Server.Execute will not work on NT, only windows 2000 and higher.

    Let me know if this works for your.

  3. #3
    Join Date
    Dec 2000
    Posts
    532
    I am using a windows 2003 server. As I am not a programmer, it is hard for me to conceive where this code should go. Just what is this script supposed to do? For example, is a.asp supposed to be a page in its own or part of a larger page like an included file is.

    My objective is this. Let's say we have a page called default.asp. Depending on the day of the week, a paragraph within the page (an include file) will change. So should I use you code inplace of the present "paragraph?"

  4. #4
    Join Date
    Jan 2004
    Posts
    406
    Originally posted by Ron
    So should I use you code inplace of the present "paragraph?"
    Yes. I chose this method becase I did not know the content of your include files. But if they are just text then you can do this if you are more comfortable...
    Code:
    <body>
         <p>
    <%
    Select Case Day(Date()) ' This will return the day of the week as a number
         Case 1%>
              <!-- #include file="a.inc" -->
    <%Case 2%>
              <!-- #include file="b.inc" -->
    <%Case 3%>
              <!-- #include file="c.inc" -->
    <%Case 4%>
              <!-- #include file="d.inc" -->
    <%Case 5%>
              <!-- #include file="e.inc" -->
    <%Case 6%> 
              <!-- #include file="f.inc" -->
    <%Case 7%>
              <!-- #include file="g.inc" -->
    <%
    End Select
    %>
         </p>
    </body>
    I have not tested it but that should do it. It is also a lot messier that way.

  5. #5
    Join Date
    Dec 2000
    Posts
    532
    So this will choose a different include file every day of the week? I am curious to know what you mean by messier. You mean because of the include tags? The source code will be seamless right? I will try this tomorrow as it is after midnight where I am. Thanks a million! I will have all sorts of fun with this.


    BTW, is there a way to do this for pages that have .htm of .shtml file endings? What language would work, JS? I guess PHP would require the .php file ending, right?

  6. #6
    Join Date
    Dec 2000
    Posts
    532
    Oh, I amost forgot to ask. In the example above, does case 1 - Sunday or just the first day that the script is run on the server?

  7. #7
    It will return a number between 1 and 31.
    Regards, Sam. www.protecweb.co.uk
    Windows Shared and Reseller Hosting with ASP.Net, MS SQL 2008, PHP, MySQL5 and more.
    Providing quality web hosting and support since 2001.

  8. #8
    Join Date
    Dec 2000
    Posts
    532
    So will the script in the above examples rotate every 7 days? If I were to use the above script as it is, would the first day I started it be case 1?

  9. #9
    No the script above will only switch the includes for the first 7 days of the month and then it will be missing for the rest.
    How many includes are you planning on having? That will determine the best way to do this.
    Regards, Sam. www.protecweb.co.uk
    Windows Shared and Reseller Hosting with ASP.Net, MS SQL 2008, PHP, MySQL5 and more.
    Providing quality web hosting and support since 2001.

  10. #10
    Join Date
    Jan 2004
    Posts
    406
    If you want it to return 1 - 7 (which is what I meant to do) use WeekDay(Date()) instead of Day(Date()) . 1 should be Sunday.

  11. #11
    Join Date
    Dec 2000
    Posts
    532
    It works! And it worked the first time - cool! Thanks a million! I will have loads of fun with this.

  12. #12
    Join Date
    Dec 2000
    Posts
    532
    Some last minute questions, if you please...


    Will this script work?

    <%
    Select Case Day(Date()) ' This will return the day of the week as a number
    Case 1%>
    <!-- #include file="a.inc" -->
    <%Case 7%>
    <!-- #include file="b.inc" -->
    <%Case 14%>
    <!-- #include file="c.inc" -->
    <%Case 21%>
    <!-- #include file="d.inc" -->
    <%
    End Select
    %>

    In other words, would it call a different include file each week?

  13. #13
    Join Date
    Jan 2004
    Posts
    406
    That will pull the proper .inc file on the 1st, 7th, 14th and 21st of the month. It will not pull any files in on the other days.

  14. #14
    Join Date
    Dec 2000
    Posts
    532
    I see, so if you want to do this script on a daily basis and have at least one include file each and every day, the script should consist of all 31 Cases?

  15. #15
    Join Date
    Jan 2004
    Posts
    406
    Originally posted by Ron
    I see, so if you want to do this script on a daily basis and have at least one include file each and every day, the script should consist of all 31 Cases?
    Quick answer yes.

    There are many more things that can be done with a select statement. For example if several days will share the same file you can separate the values with a coma...
    Code:
    case 1, 3, 8, 10
    You can also use math operators...
    Code:
    case <= 7
    You can also finish it with an else statement...
    Try playing with different statements so you can get a feel for all the different possibilities.

  16. #16
    Join Date
    Dec 2000
    Posts
    532
    So it would be written like this?

    <%
    Select Case Day(Date())
    Case 1, 3, 8, 10%>

    Also, if you have case 31 but there are only 30 days in the current month, it just ignores the 31st???

  17. #17
    Join Date
    Jan 2004
    Posts
    406
    Yes, and yes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •