Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Batch File Read Log 1st line

$
0
0

Hi everyone,

I've a batch to robocopy folders every night between servers. A log file is generated and a mail is sent at the end using Blat.exe

I would like to send the mail only if the robocopy failed. The only way i see it is to read the 1st line of the log file beginning by "Command complete successfully" if robocopy running without problem

Command complete successfully.
-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows     ::     Version XP010
-------------------------------------------------------------------------------
  Started : Tue Feb 18 23:00:01 2014"

So i would like to modify my script to read this 1st line and if it's equal to "Command complete successfully", it bypass blat.exe and emil sending

Script bellow : 

@Echo off
SET dizaine=A%time:~0,1%B 
if A1B==%dizaine% goto OK 
if A2B==%dizaine% goto OK 
:ZERO 
SET dizaine=0
goto fin 
:OK 
SET dizaine=%time:~0,1%
goto fin

:FIN 

set a=%Date:~-4%-%Date:~-7,-5%-%Date:~-10,-8%_%dizaine%%Time:~-10,-9%%Time:~-8,-6%%Time:~-5,-3%
echo %a%

set logfile=C:\script\Logs\HW_database_sync%a%.log

net use H: \\x.x.x.x\SPB /USER:nobody nobody >> %logfile%

robocopy  "C:\CIS" H:\DataBase\D /MIR /COPY:DAT /V /FP /NP /LOG+:%logfile% /FFT /R:0 /W:0 /TEE

net use H: /delete

C:/script/blat.exe %logfile% -to servicex@xxx.com -f hw_database_sync@xxx.com -server xxx.xxx.biz

Thanks Regards


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>