Files
2024-10-14 00:08:40 +02:00

63 lines
1.7 KiB
Batchfile

@echo off
SETLOCAL
cls
set log_dir=%TEMP%
set log_file=%log_dir%\log.txt
CALL :donlog "write date to log", "date /t"
CALL :donlog "write time to log", "time /t"
CALL :donlog "save path i'm in and jump to c:\", "pushd c:"
CALL :donlog "xwatch dir", "set xw_dir=c:\xwatch"
CALL :donlog "observer dir", "set ob_dir=c:\observer"
CALL :donlog "xwatch source", "set xw_src=\\10.101.0.22\pxwrelfr"
CALL :donlog "observer source", "set ob_src=\\10.101.0.24\observer"
IF EXIST %ob_dir% (
CALL :donlog "observer found", ""
CALL :donlog "unmounting z", "net use z: /delete"
CALL :donlog "mounting z", "net use z: %ob_src%"
CALL :donlog "copy files", "robocopy z: %ob_dir% /e /copyall"
CALL :donlog "unmounting z", "net use z: /delete"
) ELSE (
CALL :donlog "observer not found", ""
CALL :donlog "skipping copy", ""
)
IF EXIST %xw_dir% (
CALL :donlog "xwatch found", ""
CALL :donlog "unmounting z", "net use z: /delete"
CALL :donlog "mounting z", "net use z: %xw_src%"
CALL :donlog "copy files", "robocopy z: %xw_dir% /e /copyall"
CALL :donlog "unmounting z", "net use z: /delete"
) ELSE (
CALL :donlog "xwatch not found", ""
CALL :donlog "skipping copy", ""
)
CALL :donlog "jump back to saved path", "popd"
CALL :donlog "end", ""
rem ENDS THIS SCRIPT
goto END
rem DEFINE FUNCTIONS
rem DO aNd LOG
rem write content of first parameter to log
rem if second paramter is not empty write content to log and run content as command
rem writes empty line to log
rem returns to script
:donlog
echo %~1 >> %log_file% 2>&1
if "%~2" == "" GOTO NOTHING
echo %~2 >> %log_file% 2>&1
%~2 >> %log_file% 2>&1
:NOTHING
echo. >> %log_file% 2>&1
EXIT /B 0
rem BYE BYE
:END