Solved

Run a VBS every 30 minutes on W2K Server

Posted on 2011-02-10
15
1,126 Views
Last Modified: 2012-05-11
Because schtasks.exe does not run on Windows 2000 Server, and the AT command does not have this feature to allow me to schedule a vbs script to run every 30 minutes using something like:
/MO modifier
A value that refines the schedule type to allow for finer control over the schedule recurrence. Valid values are: MINUTE: 1 - 1439 minutes.

How would you recommend to have a vbs script to run every 30 minutes on a daily basis?  My vbs script basically reads a log file to capture errors.  It needs to run 7 days a week.
I attempted this batch job using the sleep function, but it runs a second instance only:
@echo off
:label1
cscript "D:\IVR\Utilities\ivrmonitor.vbs"
sleep 1800
goto label1
0
Comment
Question by:danfiggolf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +3
15 Comments
 
LVL 20

Accepted Solution

by:
edster9999 earned 100 total points
ID: 34866546
On a 2000 box you go into control panel and 'schedule task' and fill in the wizzard.
I think you can set it up with a repeat like that but I cannot remember the options and I do not have a 2000 box to test it on (I have burried all of them)
0
 
LVL 1

Expert Comment

by:GabelstaplerfahrerKlaus
ID: 34866581
The cscript line should be preceded by CALL, I think. Give that a try.
0
 
LVL 1

Expert Comment

by:GabelstaplerfahrerKlaus
ID: 34866620
I just tested your batch script with a second batch file as code, the Call makes it run the loop continuously. One problem though: SLEEP is not a batch command you can use.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:danfiggolf
ID: 34866665
Use call like this?  So it loops - is this a good method?

@echo off
cscript "D:\IVR\Utilities\ivrmonitor.vbs"
SLEEP 1800
CALL this-same-batch-file-again.bat
EXIT
0
 
LVL 1

Expert Comment

by:GabelstaplerfahrerKlaus
ID: 34866686
An endless loop with the TIME /T command and FINDSTR like so

time /t | findstr /c:"30" would return the string "0X:30 PM" every hour
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 34866872
"It needs to run 7 days a week...every 30 minutes on a daily basis"

Why not make the SCRIPT itself run endlessly and only do something every 30 minutes?
Dim targetTime
targetTime = DateAdd("n", 30, Now) ' 30 minutes from now

While True
    ' check every 5 seconds to see if our targetTime has been passed
    While targetTime > Now
        WScript.Sleep 5000 ' (max is 32,767 --> approx 30 seconds)
    Wend

    ' ******************************
    ' ... do your processing here...
    ' ******************************

    ' set next "event" for 30 minutes out...
    targetTime = DateAdd("n", 30, Now) ' 30 minutes from now
Wend

Open in new window

0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34866966
I believe the solution provided by edster9999 (#a34866546) is the most robust one.  Does anyone see a problem with it?
0
 

Author Comment

by:danfiggolf
ID: 34867269
@idlemind - you mean like this?
Dim targetTime
targetTime = DateAdd("n", 30, Now) ' 30 minutes from now

While True
    ' check every 5 seconds to see if our targetTime has been passed
    While targetTime > Now
        WScript.Sleep 5000 ' (max is 32,767 --> approx 30 seconds)
    Wend

    ' ******************************
    ' ... do your processing here...
    ' ******************************
    CONST strFolder = "D:\IVR\Logs\Monitor\"
	CONST ForReading = 1
	CONST ForAppending = 8

	set objShell = CreateObject("WScript.Shell")
	set objFSO = CreateObject("Scripting.FileSystemObject")

	' Create output file for report
	Set objOutput = objFSO.OpenTextfile("c:\temp\ivrFailureReport.txt", ForAppending, True)

	' Call routine to find latest file and check it for errors
	traverseDir strFolder, true, Nothing

	' Done
	objOutput.Close
	Wscript.Quit

    ' set next "event" for 30 minutes out...
    targetTime = DateAdd("n", 30, Now) ' 30 minutes from now
Wend

function traverseDir(strDir, boolSubDirs, objRecent)
    set objFolder = objFSO.GetFolder(strDir)
' Loop through IVR log file directory to determine most recent file
    for each objFile in objFolder.Files
        if objRecent Is Nothing then
            set objRecent = objFile
        elseif (objFile.DateCreated > objRecent.DateCreated) then
            set objRecent = objFile
            
        end if
    next
' Most recent log file has been identified
    if objRecent.Size > 0 Then
        Wscript.Echo "Done, most recent file = " & objRecent
        ' Open file
        Set objInput = objFSO.OpenTextfile(objRecent, ForReading)
        ' Read each line of input log file to locate IVR failure point.
        intCount = 0
        blnError = False
        Do Until objInput.AtEndOfStream
            strLine = objInput.ReadLine
            intCount = intCount + 1
            If (InStr(strLine, "Host Error|4") > 0) Then
             ' Write to the server's Application Event Log file for Whatsup Gold notification.
            Set WSHShell = CreateObject("WScript.Shell")
			WshShell.LogEvent 1, "IVR Failed with Host Error 4"
                objOutput.WriteLine strLine
                blnError = True
            ElseIf (blnError = True) Then
                objOutput.WriteLine strLine
                blnError = False
            End If
       Loop
       objInput.Close
  End If     
end function

Open in new window

0
 

Author Comment

by:danfiggolf
ID: 34867285
I believe the solution provided by edster9999 (#a34866546) is the most robust one.  Does anyone see a problem with it?  I believe so - snapshot
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 400 total points
ID: 34867428
That'll work...but you need to REMOVE line #28:

    Wscript.Quit

so that it will stay in the While loop and repeat everything after the next 30 minutes...  =)
0
 

Author Comment

by:danfiggolf
ID: 34867463
what would be better: to have the script itself manage the task repeat OR the Windows 2000 scheduler?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 34867503
Up to you.  With the scheduler the script will run and them be completely removed from memory.

*Not that it would take up that much to begin with.
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34867608
I think the scheduler is a more robust approach because:

1. If the server reboots, the scheduler will automatically continue running the script;

2. If the script itself manages the task repeat and it fails for whatever reason, the process will cease to run until someone restarts it. (not the case with the scheduler)

3. The scheduler works as a Windows Service unattended (no need for a user to be logged on to the server).

I hope this helps.
0
 
LVL 55

Expert Comment

by:Bill Prew
ID: 34867722
Definitely go the scheduler approach, much cleaner.

~bp
0
 
LVL 20

Expert Comment

by:edster9999
ID: 34873495
Hi - danfiggolf
WHen you say 'I believe so'
Did you mean you do see a problem with it or you agree that it works ?

The duration bit is the expected run time of each loop.
You would set it to be every 30 minutes with a 5 or 10 minute duration.
You can tick to stop it if it is still running at this point so you do not get multiple copies running.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question