Comment ============================================================= MarxMenu JobServer Program Copyright 1993 by Marc Perkel * All Rights Reserved This demonstration menu shows how to write a job server / scheduler in MarxMenu script. This server lets you schedule things to run base on repeating periods of time. It reads a file called SCHEDULE.ASC for it's schedule. It also can run jobs by sending messages to it using the Novell SEND command. The SCHEDULE.ASC file is a comma delimited ascii file with the following fields. Command - Dos command to execute Period - How Often in Seconds Base Time - Period Start To Run NAVYTIME.BAT weekly on Sunday at 3:15 am "NAVYTIME.BAT","604800","08-01-93 3:15" To Run DAILY.BAT once a day at 4:00 am "DAILY.BAT","86400","4:00" To Run HOUR.BAT once an hour at 15 minutes after the hour "HOUR.BAT","3600","00:15" To Run 20SEC.BAT once every 20 seconds "20SEC.BAT","20","" ============================================================= EndComment var Done Schedule RunBatch StartTime SaveNow SaveBroadcastMode Main ;======================== Procedures =========================== ;----- The Event Processor executes once a second Procedure EventProcessor SaveNow = Now ;- Look for message sends ProcessSend ;- Update schedule every 10 minutes (600 seconds) if EventReady(600,StartTime) ReadSchedule endif ;- See if it's time to do anything CheckSchedule EndProc ;----- If you send a message to the job server it will execute it Procedure ProcessSend var Message SendConnection UMessage Message = NovGetMessage if Message = '' then Return SendConnection = 0 if Left(Message,4) = "From" delete(Message,1,pos('[',Message)) SendConnection = Value(Left(Message,pred(pos(']',Message)))) Delete(Message,1,pos(':',Message)) endif Trim(Message) UMessage = UpperCase(Message) if SendConnection <> 0 ;- Reply to Sender NovSendMessage('Executing: ' + Message,SendConnection) endif ;- Sending "EXIT" will exit program if UMessage = 'EXIT' Done = True else BatchRun(Message) endif EndProc ;----- Returns True if Event is ready Procedure EventReady (Period, BaseTime) Return SaveNow - BaseTime mod Period = 0 EndProc ;----- Checks the schedule to see if anything is ready to run Procedure CheckSchedule var Command Loop Schedule if EventReady(LoopVal[2],LoopVal[3]) BatchRun(LoopVal[1]) endif EndLoop EndProc Procedure BatchRun (Command) if Extension(Command) = 'BAT' then Command = 'CALL ' + Command Bat Command RunBatch = True EndProc ;----- Reads in the schedule Procedure ReadSchedule var Command Period BaseTime ClearScreen Writeln 'Command: Period: BaseTime:' Writeln '------------------------------------------------------------------------' ReadAscTextFile('SCHEDULE.ASC',Schedule) loop Schedule LoopVal[2] = Value LoopVal[2] LoopVal[3] = TimeOf(LoopVal[3]) Command = LoopVal[1] length(Command) = 45 Period = Str(LoopVal[2]) Period = PadLeft(Period,8) BaseTime = LoopVal[3] if BaseTime = 0 BaseTime = '' else if DateString(BaseTime) = DateString(Today) BaseTime = TimeString(BaseTime) else BaseTime = DateString(BaseTime) + ' ' + TimeString(BaseTime) endif endif Writeln Command Period ' ' BaseTime endloop EndProc Procedure Main Setup Repeat ;- Wait is Multitasker friendly if running Windows or DesqView Wait 30 if KbdReady if ReadKey = F10 then Done endif if RunBatch then ExitMenu Until Done NovBroadcastMode SaveBroadcastMode EndProc Procedure Setup BoxInsideColor Grey Blue BoxBorderColor Green Blue if ColorScreen BoxHeaderColor Yellow Mag else BoxHeaderColor Black Grey endif ClockColor Grey Blue ClearScreen BlankTime = 0 SaveBroadcastMode = NovBroadcastMode NovBroadcastMode 3 BoxHeaderRight ' * MarxMenu Job Server * ' BoxFooterRight ' * Press F10 to Exit * ' Explode Off DrawBox 1 1 ScreenWidth ScreenHeight Writeln TextColor Green Blue ClearLine 196 TextColor Grey Blue NoBoxBorder DrawBox 4 4 ScreenWidth - 5 ScreenHeight - 4 ClockPos 4 2 UpperCaseOnly StartTime = Now ReadSchedule SetTimerTask (loc EventProcessor,18) EndProc