0

I have got a number of batch scripts that we are currently running manually on local machines. I am planning to move these scripts onto our windows 2003 server and set up an automated task using the scheduler to run them every 4 hours.

I have no issues setting this up but the only reason we are doing this manually at the moment is in case the batch does not finish.

Is there a way to have the scheduler check if the batch has finished running and if it has not to run another event?

I imagine it might need some kind of time frame, say if it has not finished within 1 hour to report a problem as sometimes the scripts can take a long time.

Any advice on a better solution or if this is possible is greatly appreciated.

Thanks, Simon

Edit:

Added batch related tags, as I am doing this all via Batch files another option could be to add some code in my scipts that checks the runtime and reports an error and terminates if it was been running for say 2 hours.

I however have no idea how to accomplish this, will do a google but if anyone knows a way this could be another option. I know I do have to post some code that I have tried first before asking a question for "what script" can I use so will try something out first.

Community
  • 1
  • 1
Simon Staton
  • 4,345
  • 4
  • 27
  • 49
  • What this batch files are doing? If they are an alternative to a web process, you can use http://atrigger.com for Error handling and repeating requests. –  Sep 04 '13 at 08:00
  • The batch is running an ftp download and upload, as well as some local operations like moving files around and checking file creation date and size. The event runs one file `download.bat` which goes on to run about 5 other .bats that delete files locally, move files locally etc then finally reupload to ftp. – Simon Staton Sep 04 '13 at 14:28
  • At this moment, I think writing a simple Desktop App to do this tasks and handle exceptions is a good idea. –  Sep 04 '13 at 19:48
  • I see, if its possible to do this via batch then that is also an option, have the batch check on each run for a timeout for example then trigger an event, so actually doing this outside of the task mangager. – Simon Staton Sep 05 '13 at 08:09

1 Answers1

0

Take a look to "expect" language. http://sourceforge.net/projects/expect/ This is a extension to tcl/tk and provide a lot of things which can perfectly be used to run automated tests or control (remote) scripts and applications.

The thing you do:

Write a script where you can do some actions like starting an application or a shell or run a batch. Then you have a loop which have pairs of expected inputs and actions which should be done if these inputs are catched. And there is also a timeout clause!

Expect itself runs on all platforms I know and the scripts are portable to all OS.

We use it to run telnet sessions, running apps and batches and monitor the reactions of the DUT via serial/usb/network links. It is very flexible and easy to use. We also use expect as master script for a lot of gtest based unit tests.

Klaus
  • 24,205
  • 7
  • 58
  • 113
  • Thanks for the reply, I will look into this solution but ideally would like to stick with just the batch rather than having to rewrite the scripts but if no other suggestions this is maybe the only solution. – Simon Staton Sep 06 '13 at 09:53
  • There is no need to rewrite your scripts at all. Simply write a little expect-script which starts your batch and catch the output from your scripts. The expect script only evaluates some rules on the output of your batch file. This can be any action and it can be triggered by timeout. The timeout maybe can be used to kill the batch job or what else. As mentioned above, we also use expect only as envelope around all the other tools we use. (gtest,cpp-check,cross-compile,...). And the expect scripts run under control from jenkins front end. Feel free to ask for details! – Klaus Sep 07 '13 at 08:12
  • Awesome, I will take a look at this in the next few days seems to do what I am needing will award you the bounty – Simon Staton Sep 10 '13 at 10:13