0

I wrote a batch script to make a backup of my Thunderbird client on Windows 7. It works perfectly, but I am having issues with the logging part.

Essentially, I would like it to see what is going on in the command window when it runs, as well as to log all output to a .log file.

The problem: It logs to a file, but runs without anything in the command window. Then after it completes, it runs AGAIN, but this time displays what's happening in the command window.

Included: The script. The log file.

Script:

 @ECHO ON
rem
call :Logit>>%Desktop%\"%DATE:~7,2%.%DATE:~4,2%.%DATE:~-4%-ThunderbirdBackup".log
:Logit

echo                           Backup Start at = %date% %time%
echo Beginning Automatic Backup and Encryption for Thunderbird
echo This will take approximately 45 seconds to complete

echo Killing Thunderbird.exe
taskkill /F /IM thunderbird.exe

echo Give the computer a moment to complete task
timeout /T 3

echo Zipping to Desktop
"C:\Program Files\7-Zip\7z.exe" a -t7z %Desktop%\"%DATE:~7,2%.%DATE:~4,2%.%DATE:~-4%-ThunderbirdBackup".7z %AppData%\Thunderbird\Profiles\ -m0=lzma2 -mx3 -mmt=8 -mhe=on

echo                           Backup Complete at = %date% %time%

Thank you for any assistance you cold lend.

The log: ThunderbirdScript-Log-Pastebin

Zapp
  • 17
  • 5
  • you are probably running it twice. How do you invoke this bat file? – PA. Oct 06 '14 at 11:08
  • Just double-clicking on the .bat file. – Zapp Oct 06 '14 at 11:09
  • the bat you show does not log to a file. You must be doing something else, could you explain? – PA. Oct 06 '14 at 11:12
  • It is indeed logging to a file, I assure you. See the 3rd line of the script. – Zapp Oct 06 '14 at 11:15
  • I hijacked the code from this guy's script. Totally unrelated. I just wanted his logging functionality. See this [link](http://social.technet.microsoft.com/Forums/windows/en-US/d791f7e8-224f-460c-9580-fcfda9254ffc/windows-7-how-to-make-a-log-file-of-a-batch-job?forum=w7itprogeneral) – Zapp Oct 06 '14 at 11:16

1 Answers1

1

You are invoking the :logit "function" twice; first by call and second by running through.

Just add a goto :eof after the call and you're done.

Then , to both logging to a file and displaying in stdout, you will need to tee http://en.wikipedia.org/wiki/Tee_(command) the output of the call.

 call :logit | tee ThunderbirdBackup.log
 goto :eof

 :logit
 ...
PA.
  • 28,486
  • 9
  • 71
  • 95
  • That didn't work. I don't know why. Command window opens and disappears immediately. Script doesn't run – Zapp Oct 06 '14 at 13:22
  • I just realized `tee` is not a native windows command, so maybe you don't have it in your PATH. It's part of UNXUTILS (http://unxutils.sourceforge.net), the set of GNU utilities ported to Windows. – PA. Oct 06 '14 at 13:58