案例一:nginx启动文件
@echo off
rem 当前bat的作用
echo ==================begin========================
cls
SET NGINX_PATH=%~d0
SET NGINX_DIR=%~dp0
color 0a
TITLE Nginx 管理程序 Power By Ants (http://leleroyn.cnblogs.com)
CLS
ECHO.
ECHO. * * Nginx 管理程序 Power By Ants (http://leleroyn.cnblogs.com) *
ECHO. * update by 鑫哥 2013-03-13 *
ECHO.
:MENU
ECHO. * nginx 进程list *
tasklist|findstr /i "nginx.exe"
ECHO.
ECHO. [1] 启动Nginx
ECHO. [2] 关闭Nginx
ECHO. [3] 重启Nginx
ECHO. [4] 退 出
ECHO.
ECHO.请输入选择项目的序号:
set /p ID=
IF "%id%"=="1" GOTO start
IF "%id%"=="2" GOTO stop
IF "%id%"=="3" GOTO restart
IF "%id%"=="4" EXIT
PAUSE
:start
call :startNginx
GOTO MENU
:stop
call :shutdownNginx
GOTO MENU
:restart
call :shutdownNginx
call :startNginx
GOTO MENU
:shutdownNginx
ECHO.
ECHO.关闭Nginx......
taskkill /F /IM nginx.exe > nul
ECHO.OK,关闭所有nginx 进程
goto :eof
:startNginx
ECHO.
ECHO.启动Nginx......
IF NOT EXIST "%NGINX_DIR%nginx.exe" ECHO "%NGINX_DIR%nginx.exe"不存在
%NGINX_PATH%
cd "%NGINX_DIR%"
IF EXIST "%NGINX_DIR%nginx.exe" (
echo "start '' nginx.exe"
start "" nginx.exe
)
ECHO.OK
goto :eof
案例二:hosts文件切换
@echo off
rem 当前bat的作用
echo ==================begin========================
cls
SET NGINX_PATH=%~d0
SET NGINX_DIR=%~dp0
color 0a
TITLE Hosts 管理程序
CLS
%NGINX_PATH%
cd "%NGINX_DIR%"
:MENU
IF EXIST "%NGINX_DIR%hosts0" (
ECHO 当前环境:测试环境
%PAUSE%
)
IF EXIST "%NGINX_DIR%hosts1" (
ECHO 当前环境:正式环境
%PAUSE%
)
ECHO.
ECHO. [1] 测试环境
ECHO. [2] 正式环境
ECHO. [3] 退 出
ECHO.
ECHO.请输入选择项目的序号:
set /p ID=
IF "%id%"=="1" GOTO test
IF "%id%"=="2" GOTO formal
IF "%id%"=="3" EXIT
PAUSE
:test
IF EXIST "%NGINX_DIR%hosts1" (
ren hosts hosts0
ren hosts1 hosts
)
GOTO MENU
goto :eof
:formal
IF EXIST "%NGINX_DIR%hosts0" (
ren hosts hosts1
ren hosts0 hosts
)
GOTO MENU
goto :eof
放在 C:\Windows\System32\drivers\etc 文件下,该文件下存在“hosts”和“hosts1”或“hosts0”文件