Create batch file event

This is what I want to achieve. We have this email database that we optimize weekly. At the moment, we manually register, run the team and track the status. Optimization can take from 3 to 12 hours, which forces us to log in every few hours and check whether it is over or not. I want to create a batch file and schedule a task to run a batch file. Now, when the batch file is launched, I generate an event identifier for the event (and then I can capture this evend identifier and generate email through our monitoring system), and similarly, when optimization finishes generating the event identifier in the application log. Here is what I thought to do: -

@echo off cd C:\Program Files\Quest Software\ArchiveManager C:\WINDOWS\system32\cmd.exe /K "Archive Full Text Index Service" –optimize IF errorlevel 1 Goto Stoppd exit :Stoppd eventcreate /l application /t information /so 9999 /id 1 /d "the optimization has started " :end 

I feel really bad with batch files and scripts. Can someone please advise how to generate an event.? Thanks

+4
source share
2 answers

Firstly, the cmd /k operation should return an errorlevel of 0 if it was started correctly, so your eventcreate call should happen before your exit , and not after the label :Stoppd as you have in your example.

Secondly, if you want your archiving operation to run as the process spawned by the process, you must put start in front of the cmd line:

 start C:\WINDOWS\system32\cmd.exe /K "Archive Full Text Index Service" –optimize 

This will let your process go, and then the current console can continue and fire the 'archive has started' event.

Thirdly, in order to create an event after the completion of the archive operation, you have several options:

  • you can execute two commands together with & :

      start C: \ WINDOWS \ system32 \ cmd.exe / K "Archive Full Text Index Service" –optimize & eventcreate ... 
  • you could put your archive call and its subsequent eventcreate call in a batch file, and then call it in your cmd /k call.

      start C: \ WINDOWS \ system32 \ cmd.exe / K myArchiveAndEventBatch.bat 
+1
source

Would it be acceptable not to create an event identifier and just use an e-mail program like Blat to send e- when you want to be alerted?

0
source

Source: https://habr.com/ru/post/1302193/


All Articles