Windows under Bat Batch implementation daemon (with log)

Source: Internet
Author: User

Development Department of a core program will always be down, and then need to go manually, and the security level of this service is very high, only I can operate, make my night old can't sleep, last night really can't stand, think of the shell daemon process previously written under HP-UX, This back to a Windows bat version of the daemon, then the evening thought is very slow, called a brother let him write, go up after the effect is good, at least last night I sleep 7 hours. Early to change the program to improve a number of functions, such as recording. Realize:

Check if there is a notepad, if you want to use it as your own process name, if the process is down, it will automatically restart (will generate a start.bat in the current directory)

@echo off

Set _task=notepad.exe
Set _svr=c:/windows/notepad.exe
Set _des=start.bat

: Checkstart
for/f "Tokens=5"%%n in (' Qprocess.exe ^| find "%_task%" ') Do (
If%%n==%_task% (goto checkag) Else goto STARTSVR
)



: Startsvr
Echo%time%
Echo ******** program starts to start ********
Echo Program restarts on%time%, please check system log >> Restart_service.txt
echo Start%_svr% >%_des%
Echo Exit >>%_des%
Start%_des%
Set/p=.<nul
FOR/L%%i in (1 1) do set/p a=.<nul&ping.exe/n 2 127.0.0.1>nul
Echo.
echo Wscript.Sleep wscript.arguments (0) >%tmp%/delay.vbs
cscript//b//nologo%tmp%/delay.vbs 10000
Del%_des%/q
Echo ******** program start complete ********
Goto Checkstart


: Checkag
Echo%time% program is running normally, check again after 10 seconds.
echo Wscript.Sleep wscript.arguments (0) >%tmp%/delay.vbs
cscript//b//nologo%tmp%/delay.vbs 10000
Goto Checkstart

http://blog.csdn.net/jiangxinyu/article/details/5217342

Windows under Bat Batch implementation daemon (with log)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.