Made a script and want to output the logfile data into another file - how can I do this?

Get help for specific problems
Posts: 4
Joined: 30 Jun 2013

mihomes

I wrote a script years ago for MS SyncToy and would like to modify it for use with FreeFileSync... the only problem I am having is the log file. Currently the logfile is generated in its own file with time/date stamp. I need the output for this file written to another location as part of my script AND I do not want the normal log file written as this will be a daily backup process. Here is my current script :

syncfiles.cmd (I call this through task scheduler)

@echo off
title FreeFileSync run in progress...
echo Attempting file sync. Please wait...
sync.cmd >lastsync.log

sync.cmd (called from above)

@echo off
echo FreeFileSync Log starting at :
time /T
date /T
echo.
echo.
echo.
echo ===============================================================================
echo ##### Checking connection to office...
echo ===============================================================================
PING -n 2 -w 10 127.0.0.1 |find "TTL=" && goto EXTERNAL
goto PINGFAIL

:EXTERNAL
echo ===============================================================================
echo ##### Office is online. Checking if backup drive is available...
echo ===============================================================================
if exist E:\ goto SYNC
goto EXTERNALFAIL

:SYNC
echo.
echo.
echo.
echo ===============================================================================
echo ##### External Drive E: is plugged in. Begin syncing files...
echo ===============================================================================
cd "C:\Program Files\FreeFileSync\"
FreeFileSync.exe "C:\Program Files\FreeFileSync\test.ffs_batch"
if %ERRORLEVEL% == 0 goto SUCCESS
goto SYNCFAIL

:PINGFAIL
echo.
echo ===============================================================================
echo ##### Office connection not available. No files were synced.
goto END

:EXTERNALFAIL
echo.
echo ===============================================================================
echo ##### External Drive E: was not found. No files were synced.
goto END

:SUCCESS
echo ===============================================================================
echo ##### FreeFileSync finished successfully.
goto END

:SYNCFAIL
echo ===============================================================================
echo ##### FreeFileSync completed, but with errors. See error log for details.
goto END

:END
echo ===============================================================================
echo.
echo.
echo.
echo Synctoy Log ending at :
time /T
date /T


-----------

Basically all this does is run the sync job and output a nicely formatted logfile you can view called lastsync.log.

That file will look something like this :

FreeFileSync Log starting at :
09:48 PM
Sat 06/29/2013



===============================================================================
##### Checking connection to office...
===============================================================================
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
===============================================================================
##### Office is online. Checking if backup drive is available...
===============================================================================



===============================================================================
##### External Drive E: is plugged in. Begin syncing files...
===============================================================================
===============================================================================
##### FreeFileSync finished successfully.
===============================================================================



FreeFileSync Log ending at :
09:49 PM
Sat 06/29/2013

When I was using synctoy the output was automatically written into this file. Now, I would like to do the same thing with FreeFileSync. All I need is a way to output the same information that is written into the ffs log into mine.

Anyone? Would really appreciate some assistance with this and I am sure it will be useful to others as well. Thanks!
Posts: 4
Joined: 30 Jun 2013

mihomes

I wrote a script years ago for MS SyncToy and would like to modify it for use with FreeFileSync... the only problem I am having is the log file. Currently the logfile is generated in its own file with time/date stamp. I need the output for this file written to another location as part of my script AND I do not want the normal log file written as this will be a daily backup process. Here is my current script :

syncfiles.cmd (I call this through task scheduler)

@echo off
title FreeFileSync run in progress...
echo Attempting file sync. Please wait...
sync.cmd >lastsync.log

sync.cmd (called from above)

@echo off
echo FreeFileSync Log starting at :
time /T
date /T
echo.
echo.
echo.
echo ===============================================================================
echo ##### Checking connection to office...
echo ===============================================================================
PING -n 2 -w 10 127.0.0.1 |find "TTL=" && goto EXTERNAL
goto PINGFAIL

:EXTERNAL
echo ===============================================================================
echo ##### Office is online. Checking if backup drive is available...
echo ===============================================================================
if exist E:\ goto SYNC
goto EXTERNALFAIL

:SYNC
echo.
echo.
echo.
echo ===============================================================================
echo ##### External Drive E: is plugged in. Begin syncing files...
echo ===============================================================================
cd "C:\Program Files\FreeFileSync\"
FreeFileSync.exe "C:\Program Files\FreeFileSync\test.ffs_batch"
if %ERRORLEVEL% == 0 goto SUCCESS
goto SYNCFAIL

:PINGFAIL
echo.
echo ===============================================================================
echo ##### Office connection not available. No files were synced.
goto END

:EXTERNALFAIL
echo.
echo ===============================================================================
echo ##### External Drive E: was not found. No files were synced.
goto END

:SUCCESS
echo ===============================================================================
echo ##### FreeFileSync finished successfully.
goto END

:SYNCFAIL
echo ===============================================================================
echo ##### FreeFileSync completed, but with errors. See error log for details.
goto END

:END
echo ===============================================================================
echo.
echo.
echo.
echo Synctoy Log ending at :
time /T
date /T


-----------

Basically all this does is run the sync job and output a nicely formatted logfile you can view called lastsync.log.

That file will look something like this :

FreeFileSync Log starting at :
09:48 PM
Sat 06/29/2013



===============================================================================
##### Checking connection to office...
===============================================================================
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
===============================================================================
##### Office is online. Checking if backup drive is available...
===============================================================================



===============================================================================
##### External Drive E: is plugged in. Begin syncing files...
===============================================================================
===============================================================================
##### FreeFileSync finished successfully.
===============================================================================



FreeFileSync Log ending at :
09:49 PM
Sat 06/29/2013

When I was using synctoy the output was automatically written into this file. Now, I would like to do the same thing with FreeFileSync. All I need is a way to output the same information that is written into the ffs log into mine.

Anyone? Would really appreciate some assistance with this and I am sure it will be useful to others as well. Thanks!mihomes
Figured it out - for anyone interested here is my updated script :

@echo off
echo FreeFileSync Log starting at :
time /T
date /T
echo.
echo.
echo.
echo ===============================================================================
echo ##### Checking connection to office...
echo ===============================================================================
PING -n 2 -w 10 127.0.0.1 |find "TTL=" && goto EXTERNAL
goto PINGFAIL



:PINGFAIL
echo ##### Office connection not available. No files were synced.
goto END



:EXTERNAL
echo ===============================================================================
echo ##### Office is online. Checking if backup drive is available...
echo ===============================================================================
if exist E:\ goto SYNC
goto EXTERNALFAIL



:EXTERNALFAIL
echo ##### External Drive E: was not found. No files were synced.
goto END



:SYNC
echo ##### External Drive E: is plugged in. Begin syncing files...
echo ===============================================================================
cd "C:\Program Files\FreeFileSync\"
FreeFileSync.exe "C:\Program Files\FreeFileSync\DailyBackup.ffs_batch"
echo.
echo.
echo.
echo.
echo.
echo ===============================================================================
echo ##### Results :
echo ===============================================================================
echo.
echo.
echo.
@echo off
FOR /F "delims=|" %%I IN ('DIR "C:\Program Files\FreeFileSync\logs\*.log" /B /O:D') DO SET NewestFile=%%I
TYPE "C:\Program Files\FreeFileSync\logs\%NewestFile%"
echo.
echo.
echo.
echo.
echo.
echo ===============================================================================
if %ERRORLEVEL% == 0 goto SYNCSUCCESS
if %ERRORLEVEL% == 1 goto SYNCWARNINGS
if %ERRORLEVEL% == 2 goto SYNCERRORS
if %ERRORLEVEL% == 3 goto SYNCABORTED
goto SYNCFAIL


:SYNCFAIL
echo ##### FreeFileSync failed.
goto END


:SYNCSUCCESS
echo ##### FreeFileSync completed successfully!
goto END



:SYNCWARNINGS
echo ##### FreeFileSync completed, but with warnings.
goto END



:SYNCERRORS
echo ##### FreeFileSync completed, but with warnings.
goto END



:SYNCABORTED
echo ##### FreeFileSync aborted.
goto END



:END
echo.
echo.
echo.
echo FreeFileSync Log ending at :
time /T
date /T