1.batch基础框架
@echo off
:: 双冒号开头是注释
:: ...
pause
2.赋值变量
set path=D:\test.sh
3.获取变量
echo %path%
4.获取当前时间
echo %date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2%
5.循环读取用户输入,直到文件存在
:readpath
set /p filename=请输入要上传的文件名:
if not exist %filename% (
echo %filename%文件不存在
goto :readpath
)
6.自定义函数
@echo off
:: ...
:: 批处理内容
:: ...
::调用函数
call :print 测试调用
pause
exit /b 0
::自定义输出日志
:print
echo 【%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2%】 %1
goto:eof
7.传输文件到linux
scp -P %remote_port% %source_path% %remote_user%@%remote_ip%:%target_path%
例如:scp -P 22 D:\test.txt root@1.1.1.1:/tmp/test.txt
8.远程执行命令
ssh -p 22 root@1.1.1.1 "df -h"
Comments