|
Answer» The purpose of this batch file is to FTP (PUT) a file to the server, then (GET) the file back to the client machine, then do the a file COMPARE between the original file and the file that was just received from the server to ensure that the file is not corrupted.
I would like to know, if someone could help me with the "f.bat" file to only append/write to the file when the output of the "comp" command is "Files are Different Sizes" and NOT append/write to the test.txt when the output for the "comp" command is "Files compare OK"
Thanks....
Here is the content of my batch file, but it append/writes to a file regardless of the output.
---------------------- Contents of f.bat ---------------------- :start
ftp -s:b1.bat 10.10.10.6
comp c:\test\junk20 c:\junk20 /D > c:\test.txt date /t >> c:\test.txt time /t >> c:\test.txt ECHO ------------- >> c:\test.txt
cls
goto start ___________________________________
---------------------- Contents of b1.bat ---------------------- test10 test10
binary hash
put c:\test\junk20
get junk20
delete junk20
quit ___________________________________
---------------------- Contents of no.asc ---------------------- N ___________________________________You are trying to do too much at once. Without the results of the compare, you cannot unconditionally use >>.
Code: [Select] ---------------------- Contents of f.bat ---------------------- :start ftp -s:b1.bat 10.10.10.6 echo N | comp c:\test\junk20 c:\junk20 /D > work.tmp if errorlevel 1 copy test.txt+work.tmp test.txt date /t >> c:\test.txt time /t >> c:\test.txt ECHO ------------- >> c:\test.txt del work.tmp cls goto start
You will have to fixup the paths.
Curious. Why the unconditonal goto start?
Hope this helps. Thanks! I will try it on Monday. This is purely for a software test lab. I use FTP at times to generate traffic across my test network to ensure that the FTP protocol works correctly through my setup. Hope this answers your question...
I will need to append the contents of the failure into the test.txt, because this test will run overnight. Should I still use > instead of >> ?My response indicated you output the results of the compare into a work file. After checking errorlevel returned by the compare (0=files equal, 1=files not equal), the work file is conditionally appended to test.txt (the copy STATEMENT with the plus symbol). The example posted above will do all that. Just fixup the paths and you should be good to go.
Your original post was unconditonally appending the output of the compare to test.txt before knowing the results of the compare. The work file is just that; it will be created and deleted during each run of the code.
Hope this helps. Thanks! The code works great, however, the date and time as well as the "----------" still gets logged in the Test.txt file regardless of the condition. Should I correct that the same WAY you have corrected the "comp" command?Sorry about that. Errorlevel CONTAINS the value of the last command run, so you'll have to IMPROVISE. You didn't mention your OS but this should work on most of them.
Code: [Select] ---------------------- Contents of f.bat ---------------------- :start ftp -s:b1.bat 10.10.10.6 echo N | comp c:\test\junk20 c:\junk20 /D > work.tmp if errorlevel 1 copy test.txt+work.tmp test.txt & date /t >> c:\test.txt & time /t >> c:\test.txt & echo ------------ >> c:\test.txt del work.tmp cls goto start
Note: create the IF statement as one line of text, the forum code box created two.
Good luck.
|