Results 1 to 17 of 17
Thread: Need simple ASP code for cronjob
-
05-18-2004, 05:37 AM #1Web Hosting Evangelist
- 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
-
05-18-2004, 08:35 AM #2Aspiring Evangelist
- 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 %>
Let me know if this works for your.
-
05-18-2004, 09:58 AM #3Web Hosting Evangelist
- 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?"
-
05-18-2004, 11:00 AM #4Aspiring Evangelist
- Join Date
- Jan 2004
- Posts
- 406
Originally posted by Ron
So should I use you code inplace of the present "paragraph?"
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>
-
05-18-2004, 11:25 AM #5Web Hosting Evangelist
- 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?
-
05-18-2004, 11:57 AM #6Web Hosting Evangelist
- 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?
-
05-18-2004, 12:03 PM #7Web Hosting Master
- Join Date
- Nov 2002
- Posts
- 578
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.
-
05-18-2004, 12:14 PM #8Web Hosting Evangelist
- 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?
-
05-18-2004, 12:20 PM #9Web Hosting Master
- Join Date
- Nov 2002
- Posts
- 578
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.
-
05-18-2004, 01:10 PM #10Aspiring Evangelist
- 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.
-
05-19-2004, 12:39 AM #11Web Hosting Evangelist
- 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.
-
05-19-2004, 11:44 AM #12Web Hosting Evangelist
- 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?
-
05-19-2004, 01:21 PM #13Aspiring Evangelist
- 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.
-
05-19-2004, 09:57 PM #14Web Hosting Evangelist
- 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?
-
05-20-2004, 08:52 AM #15Aspiring Evangelist
- 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?
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
Code:case <= 7
Try playing with different statements so you can get a feel for all the different possibilities.
-
05-21-2004, 01:40 AM #16Web Hosting Evangelist
- 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???
-
05-21-2004, 08:48 AM #17Aspiring Evangelist
- Join Date
- Jan 2004
- Posts
- 406
Yes, and yes