Batch Processing: two or three examples

Source: Internet
Author: User
Tags eol schtasks
I. SchTasks

With SchTasks, we can schedule tasks on the local server or remote server, which is quite useful when we need to automate tasks on multiple servers and reduce tedious work, the batch processing code I used is provided below for your reference:

REM Global variableset logfile=schedule.txtset /p choose=Please choose (1: for "Close Menu for Account", 2: for "Open Menu for Account"):if "%choose%"=="1" goto CLOSE if "%choose%"=="2" goto OPENgoto EXIT:CLOSEecho ... Close Menu for Account ...echo Start schedule at %DATE% %TIME% > %logfile% set schedule_dt=%date:~0,4%/%date:~5,2%/%date:~8,2%echo Default schedule date is %schedule_dt%, Press Enter for accepting it!set /p schedule_dt=[Please input your own schedule date:]for /f "eol='" %%i in (hosts.txt) do (  echo Host: "%%i" is executing schedule ... >> %logfile%  schtasks /change /tn "Close_Menu_for_account" /s %%i /u username /p password /sd %schedule_dt% /st 23:00:00 >> %logfile%)goto ENDING:OPENecho ... Open Menu for Account ...echo Start schedule at %DATE% %TIME% > %logfile% for /f "eol='" %%i in (hosts.txt) do (  echo Host: "%%i" is executing schedule ... >> %logfile%  schtasks /run /tn "Open_Menu_for_account" /s %%i /u username /p password >> %logfile%):ENDINGecho Finish schedule at %DATE% %TIME% >> %logfile%echo Operation finish:EXITpause

The above code has two functions: 1. Specify multiple servers to execute the set scheduled task at; 2. Execute the set tasks on multiple servers immediately.

Hosts.txt stores the IP addresses of multiple servers. The specific content is as follows:

'Web servers used
192.168.0.1
192.168.0.2
192.168.0.3
2. WebDev. WebServer

WebDev. WebServer is a lightweight Web server built in. NET framework 2.0. It is mainly used as Visual Studio. NET to debug ASP. NET programs. With this feature, we can perform a simple test on the pages we write to view the results.

@echo off:Justify whether the webserver is runningtasklist | find /i "webdev.webserver.exe" >nul 2>nul && goto KILL || goto RUN:KILLtaskkill /f /im "WebDev.WebServer.EXE" >nul 2>nul:RUNREM Suppose the VS2008 in VISTAcd /d C:\Program Files\Common Files\microsoft shared\DevServer\9.0start WebDev.WebServer.EXE /port:7736 /path:"D:\examples\tutorials\js" /vpath:"/"

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.