bat基本语法
- 注释的写法 ::
- 显示信息语句: echo
- 关闭命令行执行信息输出:echo off,
- 设置变量 set = 语句,
- 引用变量 %VAR%
- 字符串操作。
删除/: set datefmt=%datefmt:/=%
删除空格: set nametrim=%name: =%
取字串: set datefmt=%date:~0,10%
- 与用户交互:
set /p name=your Name:
- 执行外部命令
pause,date,time,echo,curl,ipconfig
- 函数定义与函数调用
call:fun_test para1 para2
函数参数引用:%1, %2
- for 语句
for %%i in () do ()
if neq ()
块语句(
::@ECHO OFF
::::::::::::::::::: set arguments ::::::::::::::::::::::::::
set WORKDIR=/tmp
set PACKER_IP=10.103.77.
set PACKER_PORT=22
set USERNAME=root
set PASSWORD=admin
set SSH_ARG=-l %USERNAME% -pw %PASSWORD% -P %PACKER_PORT%
set Path=%Path%;%cd%\tools
:: echo %Path%
echo Packing ...
for /l %%i in (1, 1, 50) do (
::set num=%%i
::echo %PACKER_IP%%%i
plink %SSH_ARG% %PACKER_IP%%%i mkdir -p %WORKDIR%
pscp -unsafe -r %SSH_ARG% %~dp0/virus %PACKER_IP%%%i:%WORKDIR%
)
::::::::::::::::::: send to the packer :::::::::::::::::::::
timeout /t 5