远端保存
@echo off
echo Trans these file to remote server:
set work_dir=D:\work_space
set temp_dir=%work_dir%\tools\remote_save
set subbatfile=%temp_dir%\remotesave.bat
set ssh_key_file=%work_dir%\tools\ssh_key\id_dsa_1024
set pack_host=
set pack_user=
set dev_type=
rem 先要根据入参截出devTpye
set tmppath=%1
FOR /F "tokens=1,2,3* delims=" %%i in ("%tmppath%") do set dev_type=%%k
FOR /F "skip=4 tokens=1,2,3* delims=" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\LocalConstruction\%dev_type%" /v HostIP') do set pack_host=%%k
FOR /F "skip=4 tokens=1,2,3* delims=" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\LocalConstruction\%dev_type%" /v UserID') do set pack_user=%%k
rem FOR /F "skip=4 tokens=1,2,3* delims=" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\LocalConstruction" /v ModuleType') do set dev_type=%%k
rem 请保证下面两个路径后面的结构相同
set src_dir=%work_dir%\%dev_type%
set remote_src_dir=/home/%pack_user%/%dev_type%
rem 自动读取传入的参数
echo cd %src_dir% > %subbatfile%
:get_opts
if not "%1" == "" (
call %temp_dir%\strstr.bat %1
shift
goto get_opts
)
call %subbatfile%
del /f %subbatfile%
ping /n 1 127.0.0.1 >nul
rem pause
strstr.bat
@echo off
set remote_dir=/home/zwx20260/aap
set file_path=%1
set src_dir_d=%src_dir%
if not %src_dir_d:~-1%=="" set src_dir_d=%src_dir_d%\
call :GetStrLen %src_dir_d% dnum
set relativefile=%file_path%
if not defined relativefile goto :eof
set myReturn=0
:Getrelativefile
set /a myReturn+=1
set relativefile=%relativefile:~1%
if not %dnum%==%myReturn% goto Getrelativefile
set str1=%relativefile:\=/%
echo scp -i %ssh_key_file% %relativefile% root@%pack_host%:%remote_src_dir%/%str1% >> %subbatfile%
goto :eof
rem ##############################################################################################
rem 获取字符串的长度
:GetStrLen
set str=%1
call :stringlenth "%str%" num
set %2=%num%
:StringLenth
set theString=%~1
if not defined theString goto :eof
set Return=0
:StringLenth_continue
set /a Return+=1
set thestring=%thestring:~1%
if defined thestring goto StringLenth_continue
if not "%2"=="" set %2=%Return%
goto :eof
::目标格式scp -i file src\aap_plugin\AapImplementInterface.cpp root@0.0.0.0:/home/zwx20260/aap/src/aap_plugin/AapImplementInterface.cpp
rem ##############################################################################################