案例一:nginx启动文件

  1. @echo off
  2. rem 当前bat的作用
  3. echo ==================begin========================
  4. cls
  5. SET NGINX_PATH=%~d0
  6. SET NGINX_DIR=%~dp0
  7. color 0a
  8. TITLE Nginx 管理程序 Power By Ants (http://leleroyn.cnblogs.com)
  9. CLS
  10. ECHO.
  11. ECHO. * * Nginx 管理程序 Power By Ants (http://leleroyn.cnblogs.com) *
  12. ECHO. * update by 鑫哥 2013-03-13 *
  13. ECHO.
  14. :MENU
  15. ECHO. * nginx 进程list *
  16. tasklist|findstr /i "nginx.exe"
  17. ECHO.
  18. ECHO. [1] 启动Nginx
  19. ECHO. [2] 关闭Nginx
  20. ECHO. [3] 重启Nginx
  21. ECHO. [4] 退
  22. ECHO.
  23. ECHO.请输入选择项目的序号:
  24. set /p ID=
  25. IF "%id%"=="1" GOTO start
  26. IF "%id%"=="2" GOTO stop
  27. IF "%id%"=="3" GOTO restart
  28. IF "%id%"=="4" EXIT
  29. PAUSE
  30. :start
  31. call :startNginx
  32. GOTO MENU
  33. :stop
  34. call :shutdownNginx
  35. GOTO MENU
  36. :restart
  37. call :shutdownNginx
  38. call :startNginx
  39. GOTO MENU
  40. :shutdownNginx
  41. ECHO.
  42. ECHO.关闭Nginx......
  43. taskkill /F /IM nginx.exe > nul
  44. ECHO.OK,关闭所有nginx 进程
  45. goto :eof
  46. :startNginx
  47. ECHO.
  48. ECHO.启动Nginx......
  49. IF NOT EXIST "%NGINX_DIR%nginx.exe" ECHO "%NGINX_DIR%nginx.exe"不存在
  50. %NGINX_PATH%
  51. cd "%NGINX_DIR%"
  52. IF EXIST "%NGINX_DIR%nginx.exe" (
  53. echo "start '' nginx.exe"
  54. start "" nginx.exe
  55. )
  56. ECHO.OK
  57. goto :eof

nginx.rar

案例二:hosts文件切换

  1. @echo off
  2. rem 当前bat的作用
  3. echo ==================begin========================
  4. cls
  5. SET NGINX_PATH=%~d0
  6. SET NGINX_DIR=%~dp0
  7. color 0a
  8. TITLE Hosts 管理程序
  9. CLS
  10. %NGINX_PATH%
  11. cd "%NGINX_DIR%"
  12. :MENU
  13. IF EXIST "%NGINX_DIR%hosts0" (
  14. ECHO 当前环境:测试环境
  15. %PAUSE%
  16. )
  17. IF EXIST "%NGINX_DIR%hosts1" (
  18. ECHO 当前环境:正式环境
  19. %PAUSE%
  20. )
  21. ECHO.
  22. ECHO. [1] 测试环境
  23. ECHO. [2] 正式环境
  24. ECHO. [3] 退
  25. ECHO.
  26. ECHO.请输入选择项目的序号:
  27. set /p ID=
  28. IF "%id%"=="1" GOTO test
  29. IF "%id%"=="2" GOTO formal
  30. IF "%id%"=="3" EXIT
  31. PAUSE
  32. :test
  33. IF EXIST "%NGINX_DIR%hosts1" (
  34. ren hosts hosts0
  35. ren hosts1 hosts
  36. )
  37. GOTO MENU
  38. goto :eof
  39. :formal
  40. IF EXIST "%NGINX_DIR%hosts0" (
  41. ren hosts hosts1
  42. ren hosts0 hosts
  43. )
  44. GOTO MENU
  45. goto :eof

放在 C:\Windows\System32\drivers\etc 文件下,该文件下存在“hosts”和“hosts1”或“hosts0”文件