远端保存

@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 ##############################################################################################
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值