home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
pcc
/
v08n03
/
netwrk.exe
/
CLONE1_1.ZIP
/
CLONE.BAT
< prev
next >
Wrap
DOS Batch File
|
1993-01-07
|
16KB
|
410 lines
echo off
if "%1"==".entry2" goto entry2
if "%1"==".sub1" goto sub1
if "%1"==".sub2" goto sub2
if "%1"==".sub3" goto sub3
if "%2"==".sub4" goto sub4
if "%2"==".sub5" goto sub5
if "%1"==".sub6" goto sub6
if "%1"==".sub7" goto sub7
echo CLONE vs. 1.1 sends a complete drive, or a part of it (branch) serially to
echo another machine into a specific subdirectory. (c) 1993, Jim Groeneveld, NL
echo.
rem Necessary auxiliary files: SUBST.*, FIND.* (DOS) and DISK.COM, ZIP.COM (vs. 1.51);
if "%1"=="" goto help
if "%1"=="?" goto help
if "%1"=="/?" goto help
if "%1"=="-?" goto help
if "%1"=="/h" goto help
if "%1"=="/H" goto help
echo Wait.............processing arguments..................
for %%a in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do if "%%a"==".s" goto repeat_1
for %%a in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do if "%%a"==".S" goto repeat_1
goto chk_tmp
:repeat_1
%0 .sub1 %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
rem never pass here!
:entry2
shift
shift
if "%1"=="" goto help
goto no_filspec
:chk_tmp
if not exist $dirlist.bat goto no_dirlist
echo *** Temporary file $DIRLIST.BAT already exists, cannot proceed;
echo remove or rename $DIRLIST.BAT or specify '.s' option.
goto end
:no_dirlist
if not exist $ziplist.bat goto no_ziplist
echo *** Temporary file $ZIPLIST.BAT already exists, cannot proceed;
echo remove or rename $ZIPLIST.BAT or specify '.s' option.
goto end
:no_ziplist
if not exist $fillist.bat goto no_fillist
echo *** Temporary file $FILLIST.BAT already exists, cannot proceed;
echo remove or rename $FILLIST.BAT or specify '.s' option.
goto end
:no_fillist
if not exist $filspec.bat goto no_filspec
echo *** Temporary file $FILSPEC.BAT already exists, cannot proceed;
echo remove or rename $FILSPEC.BAT or specify '.s' option.
goto end
:no_filspec
if exist $dirlist.bat del $dirlist.bat
if exist $dirlist.bat goto $dirlist
if exist $ziplist.bat del $ziplist.bat
if exist $ziplist.bat goto $ziplist
if exist $fillist.bat del $fillist.bat
if exist $fillist.bat goto $fillist
if exist $filspec.bat del $filspec.bat
if exist $filspec.bat goto $filspec
rem Search %2 for file specification: a. empty
if "%2"=="" goto nofilespec
rem b. Search %2 for starting '/', if so: parameter (see file UNDOCU'D.DOS)
for %%b in (/%2) do if %%b==/ goto nofilespec
rem c. Search %2 for starting '.', if so: parameter (see file UNDOCU'D.DOS)
for %%b in (/%2) do if %%b==. goto nofilespec
:file_spec
rem if "%1"=="\" goto error1 These subst path specifications appear to
rem if "%1"=="." goto error1 work correctly, as does any relative path
rem if "%1"==".." goto error1 specification, at least with DOS 3.3 .
for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do if "%1"=="%%a" goto error1
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if "%1"=="%%a" goto error1
for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do if "%1"=="%%a:" goto error1
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if "%1"=="%%a:" goto error1
if "%1"=="z:\" goto error1
if "%1"=="Z:\" goto error1
for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y) do if "%1"=="%%a:\" goto begin
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y) do if "%1"=="%%a:\" goto begin
if exist %1 goto is_file
if exist %1\*.* goto begin
ctty nul
rem>%1\$chkpath.nul
ctty con
if not exist %1\$chkpath.nul goto not_existing
del %1\$chkpath.nul
:begin
if exist Z:\*.* goto z_exists
ctty nul
rem>Z:\$chkpath.nul
ctty con
if not exist Z:\$chkpath.nul goto nosubstz
del Z:\$chkpath.nul
:z_exists
echo --- Existing substitution or network assignment of drive Z: will be lost;
echo drive Z will be temporarily substituted as %1
echo Restore original substitution after termination of this program:
subst|find "Z:"
net use|find "Z:"
echo (Ignore eventual "Bad command or file name" above...........)
:nosubstz
rem If Z: is write protected its existence can not be checked. So to be
rem sure Z: is being freed below from substitution or network assignment.
subst z: /d >nul
rem disconnect drive Z: from network, ignore eventual error message..........
ctty nul
net use z: /d >nul
ctty con
rem check whether Z: now indeed does not exist
if not exist Z:\*.* goto mount
ctty nul
rem>Z:\$chkpath.nul
ctty con
if not exist Z:\$chkpath.nul goto mount
del Z:\$chkpath.nul
echo *** Existing drive Z:\ could not be disconnected successfully.
echo It still may be ASSIGNed or otherwise existing. Program abort!
goto beep
:mount
rem substitute Z: to specified drive:\path to transfer
subst z: %1 >nul
rem and check whether substitution succeeded
if exist Z:\*.* goto zz_exists
ctty nul
rem>Z:\$chkpath.nul
ctty con
if not exist Z:\$chkpath.nul goto no_z_nul
del Z:\$chkpath.nul
:zz_exists
echo --- Cloning branch: %1, file specification: %2
if not "%3"=="" echo Additional option(s): %3 %4 %5 %6 %7 %8 %9
rem Create beginning of subdirectory listing:
echo echo off>$dirlist.bat
if not exist $dirlist.bat goto nodirlist
echo --- Create subdirectory listing (root not included), wait.....................
ctty nul
disk /d /b z:>>$dirlist.bat
ctty con
command/c$dirlist echo
rem Process $DIRLIST.BAT with "%1 d:\path %2" lines into $FILLIST.BAT with
rem "%2 %3 %4 %5 d:\path\%1 %6 %7 %8 %9" lines
echo echo off>$fillist.bat
if not exist $fillist.bat goto nofillist
echo %%2 %%3 %%4 %%5 Z:\%%1 %%6 %%7 %%8 %%9>>$fillist.bat
ctty nul
command/c$dirlist command/c%0 .sub5
ctty con
rem Create $FILSPEC.BAT containing "shift║%0 %1 filespec %2 %3 %4 %5 %6 %7 %8 %9"
rem ('shift' in order not to output $FILSPEC as %0 when used later from REPLICA,
rem but REPLICA, to insert FILESPEC as %2 and to keep all other 7 parameters.)
echo echo off>$filspec.bat
if not exist $filspec.bat goto nofilspec
echo shift>>$filspec.bat
echo %%0 .filspec %%0 %%1 %2 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>>$filspec.bat
echo --- transfer subdirectory structure $DIRLIST.BAT, filelist $FILLIST.BAT
echo and filespec $FILSPEC.BAT
rem with only optional COM port and/or baudrate parameter
command/c%0 .sub2 %0 %3 %4 %5 %6 %7 %8 %9
rem Process $DIRLIST.BAT with "%1 d:\path %2" lines into $ZIPLIST.BAT with
rem "zip d:\path\%1 /[d:\path] %2 %3 %4 %5 %6 %7 %8" lines
echo echo off>$ziplist.bat
if not exist $ziplist.bat goto noziplist
echo zip Z:\%%1 /[Z:\] %%2 %%3 %%4 %%5 %%6 %%7 %%8>>$ziplist.bat
ctty nul
command/c$dirlist command/c%0 .sub4
ctty con
echo --- transfer all files, wait for receiver creating subdir structure
command/c%0 .sub6 %0 command/c$ziplist %2 %3 %4 %5 %6 %7 %8 %9
echo --- Unlink server
rem include all ZIP options
command/c%0 .sub6 %0 zip /u %3 %4 %5 %6 %7 %8 %9
:finish
for %%a in (%3 %4 %5 %6 %7 %8 %9) do if "%%a"==".d" goto delete
for %%a in (%3 %4 %5 %6 %7 %8 %9) do if "%%a"==".D" goto delete
goto unmount
:delete
rem check whether to delete all successfully transferred files
if not exist $filspec.bat goto unmount
echo --- Deleting file specification %2 within branch %1
command/c$fillist %2 command/c%0 .sub7
rem () can not remove the directory list from $DIRLIST.BAT:
rem 1. the directories should be processed in the reverse order, not possible;
rem 2. there may still be files in them if not the default of *.* was given;
rem 3. directories may be substituted or protected, not possible to remove.
:unmount
subst z: /d >nul
if exist $dirlist.bat del $dirlist.bat
if exist $dirlist.bat echo delete $DIRLIST.BAT yourself.
if exist $ziplist.bat del $ziplist.bat
if exist $ziplist.bat echo delete $ZIPLIST.BAT yourself.
if exist $fillist.bat del $fillist.bat
if exist $fillist.bat echo delete $FILLIST.BAT yourself.
if exist $filspec.bat del $filspec.bat
if exist $filspec.bat echo delete $FILSPEC.BAT yourself.
echo === Termination of CLONE ===
goto end
:nodirlist
echo *** Unable to create $DIRLIST.BAT.
goto explain
:nofillist
echo *** Unable to create $FILLIST.BAT.
goto explain
:nofilspec
echo *** Unable to create $FILSPEC.BAT.
goto explain
:noziplist
echo *** Unable to create $ZIPLIST.BAT.
:explain
echo Current default drive:directory may be full or the directory entry
echo table is full or the disk is write protected or it is an existing
echo subdirectory name. Take whatever precautions are necessary to solve
echo this (enable write, delete some redundant file(s)).
goto unmount
:$dirlist
echo *** Unable to delete (or overwrite later) $DIRLIST.BAT
goto $explain
:$ziplist
echo *** Unable to delete (or overwrite later) $ZIPLIST.BAT
goto $explain
:$fillist
echo *** Unable to delete (or overwrite later) $FILLIST.BAT
goto $explain
:$filspec
echo *** Unable to delete (or overwrite later) $FILSPEC.BAT
:$explain
echo File and/or disk may be write protected, unprotect it/them.
goto end
:error1
echo *** Illegal source path specification %1 ***
goto beep
:no_z_nul
echo *** Impossible to install auxiliary substituted drive Z:.
echo - Maybe the external DOS SUBST command is not available.
echo - Maybe the necessary line "LASTDRIVE=Z" lacks in CONFIG.SYS.
echo - Maybe an already substituted or network drive has been specified;
echo only logical drives may be specified.
echo - Maybe an original drive Z: is write protected.
echo - Maybe the disk with %1 is write protected.
echo - Or maybe a wrong syntax has been applied (see below).
echo Correct and try again.
goto beep
:not_existing
echo *** Specified «drive»«path» %1 does not exist or is write protected.
echo Remove eventual protection (for check). Program abort!
goto beep
:is_file
echo *** Specified «drive»«path» %1 is a file, not a subdirectory.
echo Program abort!
goto beep
:beep
echo
pause
:help
echo Usage: "CLONE «drive»«path» [«filespec»] [options]" of subdirectory to
echo transfer, including all subdirectories below (branches),
echo with «drive» = logical (not substituted) drive A..Y (not Z:),
echo and «path» = complete pathname, without trailing \, unless root,
echo and [«filespec»]= optional file specification, wildcard (default *.*),
echo and [options] = one or more of optional parameters below:
echo .s : skip initial test for temporary scratch files
echo .d : delete specified files after successful transfer
echo ( /1│/2│/3│/4 : COM port number
echo ( /P : prompt for each file
echo see also ( /N : no overwrite (default overwrite)
echo ZIP.DOC ( /E : send only already existing files (useless in this case)
echo ( /T : overwrite only older files, not newer ones
echo ( /Bbaudrate : sets baudrate
echo Example: "CLONE C:\" or "CLONE D:\WORK\TEXTS *.TXT /2 .S /t .d".
echo.
echo On the receiving end the following has to be entered:
echo "REPLICA «drive»«path» [options]" of receiving subdirectory.
goto end
:sub1
shift
shift
rem Remove .s .S from parameters and restart batch file................
for %%a in (s S) do if "%1"==".%%a" %0 .sub1 %0 %2 %3 %4 %5 %6 %7 %8 %9
for %%a in (s S) do if "%2"==".%%a" %0 .sub1 %0 %1 %3 %4 %5 %6 %7 %8 %9
for %%a in (s S) do if "%3"==".%%a" %0 .sub1 %0 %1 %2 %4 %5 %6 %7 %8 %9
for %%a in (s S) do if "%4"==".%%a" %0 .sub1 %0 %1 %2 %3 %5 %6 %7 %8 %9
for %%a in (s S) do if "%5"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %6 %7 %8 %9
for %%a in (s S) do if "%6"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %5 %7 %8 %9
for %%a in (s S) do if "%7"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %5 %6 %8 %9
for %%a in (s S) do if "%8"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %5 %6 %7 %9
for %%a in (s S) do if "%9"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %5 %6 %7 %8
%0 .entry2 %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
rem never pass here!
:sub2
shift
shift
rem Remove /p /n /e /t /P /N /E /T .d .D temporarily from parameters and execute
rem 'ZIP $DIRLIST.BAT,$FILLIST.BAT,$FILSPEC.BAT ...'
rem only with Com port and Baudrate parameters
for %%a in (p n e t P N E T) do if "%1"=="/%%a" %0 .sub2 %0 %2 %3 %4 %5 %6 %7
for %%a in (p n e t P N E T) do if "%2"=="/%%a" %0 .sub2 %0 %1 %3 %4 %5 %6 %7
for %%a in (p n e t P N E T) do if "%3"=="/%%a" %0 .sub2 %0 %1 %2 %4 %5 %6 %7
for %%a in (p n e t P N E T) do if "%4"=="/%%a" %0 .sub2 %0 %1 %2 %3 %5 %6 %7
for %%a in (p n e t P N E T) do if "%5"=="/%%a" %0 .sub2 %0 %1 %2 %3 %4 %6 %7
for %%a in (p n e t P N E T) do if "%6"=="/%%a" %0 .sub2 %0 %1 %2 %3 %4 %5 %7
for %%a in (p n e t P N E T) do if "%7"=="/%%a" %0 .sub2 %0 %1 %2 %3 %4 %5 %6
for %%a in (d D) do if "%1"==".%%a" %0 .sub2 %0 %2 %3 %4 %5 %6 %7
for %%a in (d D) do if "%2"==".%%a" %0 .sub2 %0 %1 %3 %4 %5 %6 %7
for %%a in (d D) do if "%3"==".%%a" %0 .sub2 %0 %1 %2 %4 %5 %6 %7
for %%a in (d D) do if "%4"==".%%a" %0 .sub2 %0 %1 %2 %3 %5 %6 %7
for %%a in (d D) do if "%5"==".%%a" %0 .sub2 %0 %1 %2 %3 %4 %6 %7
for %%a in (d D) do if "%6"==".%%a" %0 .sub2 %0 %1 %2 %3 %4 %5 %7
for %%a in (d D) do if "%7"==".%%a" %0 .sub2 %0 %1 %2 %3 %4 %5 %6
zip $dirlist.bat,$fillist.bat,$filspec.bat /[] %1 %2 %3 %4 %5 %6 %7
if errorlevel 1 goto error2
echo === subdirectory structure $DIRLIST.BAT, filelist $FILLIST.BAT
echo and filespec $FILSPEC.BAT successfully transferred
:recover1
rem and return to calling point
goto end
:error2
echo *** An error occurred while sending $DIRLIST.BAT, $FILLIST.BAT and $FILSPEC.BAT
echo (see above)
goto recover1
:nofilespec
rem %2 is empty or one of the parameters beginning with a '/' or /./
rem Restart %0 with *.* as second parameter and continue from :file_spec
echo --- Default file specification *.* assumed.
%0 .sub3 %0 %1 *.* %2 %3 %4 %5 %6 %7 %8 %9
:sub3
shift
shift
goto file_spec
:sub4
echo zip %1\%%1 /[%1] %%2 %%3 %%4 %%5 %%6 %%7 %%8>>$ziplist.bat
goto exit
:sub5
echo %%2 %%3 %%4 %%5 %1\%%1 %%6 %%7 %%8 %%9>>$fillist.bat
goto exit
:sub6
shift
shift
rem Remove .d .D temporary from parameters and execute %1................
for %%a in (d D) do if "%3"==".%%a" %0 .sub6 %0 %1 %2 %4 %5 %6 %7 %8 %9
for %%a in (d D) do if "%4"==".%%a" %0 .sub6 %0 %1 %2 %3 %5 %6 %7 %8 %9
for %%a in (d D) do if "%5"==".%%a" %0 .sub6 %0 %1 %2 %3 %4 %6 %7 %8 %9
for %%a in (d D) do if "%6"==".%%a" %0 .sub6 %0 %1 %2 %3 %4 %5 %7 %8 %9
for %%a in (d D) do if "%7"==".%%a" %0 .sub6 %0 %1 %2 %3 %4 %5 %6 %8 %9
for %%a in (d D) do if "%8"==".%%a" %0 .sub6 %0 %1 %2 %3 %4 %5 %6 %7 %9
for %%a in (d D) do if "%9"==".%%a" %0 .sub6 %0 %1 %2 %3 %4 %5 %6 %7 %8
%1 %2 %3 %4 %5 %6 %7 %8 %9
if errorlevel 1 goto error3
if not "%2"=="/u" echo === all files successfully transferred
if "%2"=="/u" echo === server unlinked successfully
:recover3
goto exit
:error3
if not "%2"=="/u" echo *** An error occurred while sending files (see above)
rem indicate failure to transfer files by removing $FILSPEC.BAT prematurely
rem (errorlevel cannot be passed down to previous command level)
if not "%2"=="/u" if exist $filspec.bat del $filspec.bat
if "%2"=="/u" echo *** An error occurred while unlinking server (receiving end) (see above)
if "%2"=="/u" echo You may have to press ESC on the receiving end to finish !!!!!!!!!!!
goto recover3
:sub7
rem Original file specification does not need to be present in every branch:
if not exist %2 goto end
rem To automatically answer Y to eventual "Are you sure (Y/N)?" if original
rem (default) file specification is *.* (here it is preceeded by the path):
echo y|del %2>nul
if not exist %2 goto end
rem Check for successful deletion of %2 below branch %1
echo.
echo ***************************************************************************
echo !!! Warning: target file specification %2 still exists!
dir %2 /w /p
echo You may have to delete %2 yourself.
pause
goto end
:end
:exit