# Solved: output batch errors to log files



## new tech guy

Hello folks,
I have a batch script i use to backup files on the pcs in my network to a central NAS. Has an offsite tool too that runs fine but that is beside the point. What i have a problem with is that i have an xcopy line to backup files. And if it has an error i want the error to be displayed in the log file. But for some reason the redirect switch (>>pathtomyfile.txt) will not show that output nor give me the command that was used. I do not want my users to see the command but want to see it in the commandline. I hope everyone understands what im asking, anyway, here is a copy of what i am using and the scripts run on both winxp/windows vista machines.



Code:


@echo off
echo =======================NeMiSyS Filebackup Utility v4.0==========================
echo Logging into Server...
net use G: /d
net use H: /d
net use G: \\mybookworld\vincent /USER:vincent XXXXXXXXX
net use H: \\mybookworld\public
echo Modifying backup directories...
rmdir G:\laptop_backup\backup3 /s /q
rename G:\laptop_backup\backup2 backup3
rename G:\laptop_backup\backup1 backup2
rename G:\laptop_backup\backup backup1
mkdir G:\laptop_backup\backup
mkdir G:\laptop_backup\backup\firefox
echo Backing up files...
xcopy "C:\users\vincent" "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt
echo Backing up firefox profiles...
xcopy "C:\Users\Vincent\AppData\Roaming\Mozilla\Firefox\Profiles" "G:\laptop_backup\backup\firefox\" /e /q /c
echo Backup complete!


::Originally coded by JStergis
::Modified by New Tech Guy

(the XXXXXXX is a password)


----------



## TheOutcaste

OK, I'm assuming the redirection is on the command line that calls this script, as I don't see it in the script itself. Which means all the echo commands like *Logging into Server...* etc go into the log file, is this correct? The only thing that will appear on the Command Prompt window are errors.

By default, the redirection only redirects STDOUT, not STDERR. You can redirect STDERR to a file as well, but not the same file to which the STDOUT is being sent.
And, you can't output to both a file and the Command Prompt window at the same time, at least not natively. There are several apps to allow this though, search the web for *windows tee command*.
You can do it in a batch file, but you have to capture the error, read it back in, then output to the screen and then to the log file.

It is fairly simple to set up a separate file to capture errors. Use this:
backup.cmd 1>logfile.txt 2>errorlog.txt
Best to also echo a day/date line to each file at the start so you can match errors to the same run.
One problem with this is that anything that requires a user response is written to STDOUT -- and since it is being redirected, you'll never see it; for example, a prompt to overwrite an existing file. The program will appear to have hung. This shouldn't happen with this file as you are creating a new folder to backup to each time. Same thing with Control C -- you'll never see the prompt asking if you want to terminate, but if you keep hitting CTRL+C it will stop

As far as outputting the command that caused the error, you would have to turn echo on. Even then, there would be no way to match the error to a specific command, as the commands would be echoed to the log file while the error goes to the error file.

I think the best approach would be to add error checking to the commands. Errors will be redirected to a temp file. After each command, check for errors, if an error occurs, you can read the error from the temp file and echo the error and the command to the screen, which will add it to the log as all output goes to the log.

errorlevels returned by xcopy are:
*Errorlevels* 

*0* Files were copied without error
*1* No files were found to copy
*2* The user pressed CTRL+C (^C) to terminate XCOPY
*4* Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command-line
*5* Disk write error occurred

I've never seen #1 -- xcopy has always returned 0 if no files were found to copy for me. # 4 can also mean that the specified file doesn't exist. If you just need to know that an error occurred, but not the specific one, use this:



Code:


xcopy "C:\users\vincent" "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt 2>%temp%\tmp}1{.txt
If NOT ERRORLEVEL 1 GoTo _noerror1
 :: Echo the command and the error
for /f %%I in (%temp%\tmp}1{.txt) Do (
Echo This command -- xcopy "C:\users\vincent" "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt
Echo caused this error -- %%I
)
:_noerror1

Do the same for each xcopy command.

I would also suggest you change these lines:


Code:


net use G: /d
net use H: /d

to this


Code:


If Exist G:\ net use G: /d
If Exist H:\ net use H: /d

This will avoid an error if the drive is NOT mapped.

You say this is run under WinXP and Vista, but the paths shown are Vista paths . If you are using two files, one for Vista and one for XP with the paths modified for each, you can simplify things by checking to see what OS you are running on, then set the paths appropriately. That way you only have one version to maintain. So the whole thing would look like this:


Code:


@echo off
echo =======================NeMiSyS Filebackup Utility v4.0==========================
:: Check OS version to set correct paths
ver |find /I "version 6" [COLOR=Red][B]>Nul[/B][/COLOR]
If [COLOR=Red][B]%ErrorLevel% ==[/B][/COLOR] 0 goto _Vista[/b][/color]
ver |find /I "version 5" [COLOR=Red][B]>Nul[/B][/COLOR]
If [COLOR=Red][B]%ErrorLevel% ==[/B][/COLOR] 0 goto _XPor2K
Echo Unsupported Operating system:&ver
Goto:EOF
:_XPor2K
:: OS is XP or 2K
Set source1=c:\Documents and Settings\Vincent
Set source2=%source1%\Application Data\Mozilla\Firefox\Profiles
Goto _backup
:_Vista
:: OS is Vista
Set source1=C:\users\vincent
Set source2=%source1%\AppData\Roaming\Mozilla\Firefox\Profiles
[COLOR=Red][B]:_backup[/B][/COLOR]
echo Logging into Server...
If Exist G:\ net use G: /d
If Exist H:\ net use H: /d
net use G: \\mybookworld\vincent /USER:vincent XXXXXXXXX
net use H: \\mybookworld\public
echo Modifying backup directories...
rmdir G:\laptop_backup\backup3 /s /q
rename G:\laptop_backup\backup2 backup3
rename G:\laptop_backup\backup1 backup2
rename G:\laptop_backup\backup backup1
mkdir G:\laptop_backup\backup
mkdir G:\laptop_backup\backup\firefox
echo Backing up files...
xcopy "%source1%" "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt 2>%temp%\tmp}1{.txt
If [COLOR=Red][B]%ERRORLEVEL% ==[/B][/COLOR] 0 GoTo _noerror1
:: Echo the command and the error to the screen so it will end up in the log
For /F %%I in (%temp%\tmp}1{.txt) Do (
Echo This command -- xcopy "%source1%" "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt
Echo caused this error -- %%I
)
:_noerror1
echo Backing up firefox profiles...
xcopy "%source2%" "G:\laptop_backup\backup\firefox\" /e /q /c >%temp%\tmp}1{.txt
If [COLOR=Red][B]%ERRORLEVEL% ==[/B][/COLOR] 0 GoTo _noerror2
:: Echo the command and the error to the screen so it will end up in the log
For /F %%I in (%temp%\tmp}1{.txt) Do (
Echo This command -- xcopy "%source2%" "G:\laptop_backup\backup\firefox\" /e /q /c
Echo caused this error -- %%I
)
:_noerror2
echo Backup complete!

:: delete tmp files
Del /q %temp%\tmp}?{.txt


::Originally coded by JStergis
::Modified by New Tech Guy

If the above is named filebackup.cmd call it like this:



Code:


filebackup >>C:\pathtomyfile\BackupLogFile.txt

It's late and I haven't created a file structure to test this with your paths, so there may be typos or glitches I missed, so test carefully

HTH

Jerry

Edit -- Made corrections to the code, they are shown in Red


----------



## new tech guy

Thanks the outcaste, i had it running under a .bat file. Also thanks alot for explaining how to combine the two versions as as you stated, i have an xp and vista version of them for each machine on the network depending which OS im using. Also, usually the old drive mapping is there which is why i have the 
net use G: /d...etc line in there. I sent you the current version that was out which is why there was no logging going on. Also, the reason for the logging is because i have novice users who run the batch and usually dont tell me when its broken and it would take me working on the pc to find out somthing is amiss. The posted version was the one for my laptop which is vista particularly. Also, i had no logging on the one i sent you yet as i was not sure how to get the stderr part. Finally just to point out, i have a script on the machine which starts the main backup script through another batch which all it does is blast out the current backup file it has and it copies over the file from a directory on the server by logging onto it, mapping it so it can copy, then after changing the files drops the extra network connection and proceeds to the backup. Will your posted version run in a bat file or will i need some other filetype to execute it? And what would also greatly simplify things is if there is a way to just use a variable with that os check you have so that it just uses the variable to get to the active user"s backup directory. This way i dont need to chase the code around and see who im working on. I know this is a little confusing but thanks for bearing with me. And yes i want to see on the screen certain echo lines for the users (want to keep the interface simple). Therefore the front end would look like this (well what the current code shows)

[frontend]
=====================Nemisys filebackup utility v4.0======================
Logging into server....
Modifying backup directories....
Backing up files.....
Backing up firefox profiles....
Backup Complete![/frontend]


----------



## new tech guy

Ok an update, i found out how to combine the two text files into one using the type command. So i figure i can capture the stdin,stdout, and stderr command of each and after each command add a type command to combine the error file with the main log. Also that code you posted for the os choice is good, but i think i found an easier solution. However, its untested but an idea nonetheless (ive had a dummy batch i made which is being used for testing). I found out and remember it originally from the firefox help file on the location of the profile folder. I found that instead of having to use either the C:\user or C:\documents and settings , you could just type %userprofile% . And it automatically jumps to that users directory. This works in both xp and vista. I am considering parts of what you have given me however, like the if string you have for the network directories. Thirdly i have an idea for security, once the batch code is executed i am thinking of having it launch another script again which will clear the backup folder this way it helps protect the NAS logons by removing the script file which contains the logon password. Also it ensures it is always running the latest version of the script.


----------



## new tech guy

Another question for you as well, when i write this code, should I write the log for every line with action, just so i know if anything breaks down or just keep it to the copy lines? I was thinking of doing everything so i know if any line anywhere blows up for some reason but it may not be needed or necessary.


----------



## TheOutcaste

I see you found the %userprofile% variable, very handy
type Set in a command prompt to see many others, computer name, domain name, username, user profile, logon server, appdata path, program files location, etc
Using %userprofile% and %appdata% you don't even need to check which OS it is.

You can run the file as a .bat or .cmd, either works.

Lots of variations on finding the current OS.
What I posted above actually won't work as I messed up the errorlevel check.
*IF Errorlevel 0* actually does this: *If %errorlevel% GEQ 0*
so that code will always think it's on Vista.
Should check it this way (And I really should have added the Nul so the find result doesn't end up in the log):



Code:


:: Check OS version to set correct paths
ver |find /I "version 6" >Nul
If %ErrorLevel% == 0 goto _Vista
ver |find /I "version 5" >Nul
If %ErrorLevel% == 0 goto _XPor2K
Echo Unsupported Operating system:&ver
Goto:EOF

Here's a handy mnemonic to remember the Errorlevel Find returns -- f*0*und/m*1*ssing
Same with the other error checks
I also left out a label. I've edited the above post to correct that.

If the error message happens to be more than one line, a better way to output the command and error to the log is to use type.
I've done a little more tweaking and come up with this the code below.
It starts a temp log file %temp%\tmp}0{.txt
Command output is sent to %temp%\tmp}*1*{.txt
Errors are sent to %temp%\tmp}*2*{.txt
Numbers match the stdout and stderr numbers to help keep them straight

The output and errors are copied to the temp log after each command
When done, the temp log is copied to c:\Backups\TmpBackup.log
The script that starts this file can then append it to the master log on the server, or on this PC, then delete the TmpBackup.log file and the batch file to help secure the password. Note that if the user presses CTRL+C, they _can_ stop the script, then read the file to see the password though.
You could have the script download and call a separate batch file from the server that will actually do the drive mapping, then delete it. That way the file with the password won't be on the system that long. Of course, they can always read the batch file to find the name and location of the file that has the password, but at least it wouldn't be on the system that long.

Note that I added a *Set xcopycmd=xcopy /ceq* variable at the start. You then use %xcopycmd% instead of xcopy
This makes it easy to change the switches for the command as you only have to do it in one place.
and if a particular command needs an added switch, you just add it for that one command *%xcopycmd%m*
You can also use *Set switches=/ceq* then *xcopy %switches%*



Code:


@echo off
echo =======================NeMiSyS Filebackup Utility v4.0==========================
Set source1=%Userprofile%
Set source2=%AppData%\Mozilla\Firefox\Profiles
Set Destination=G:\laptop_backup\backup
Set xcopycmd=xcopy /ceq
echo Logging into Server...
If Exist G:\ net use G: /d
If Exist H:\ net use H: /d
net use G: \\mybookworld\vincent /USER:vincent XXXXXXXXX
net use H: \\mybookworld\public
echo Modifying backup directories...
rmdir %Destination%3 /s /q
rename %Destination%2 backup3
rename %Destination%1 backup2
rename %Destination% backup1
mkdir %Destination%
mkdir %Destination%\firefox
echo Backing up files...
>%temp%\tmp}0{.txt Echo ==============================
>>%temp%\tmp}0{.txt Echo Backup Job on %Computername% for %Username%
>>%temp%\tmp}0{.txt Echo Started on %date% at %time%
>>%temp%\tmp}0{.txt Echo ==============================
%xcopycmd% "%source1%" "%Destination%" 1>%temp%\tmp}1{.txt 2>%temp%\tmp}2{.txt
If %ERRORLEVEL% == 0 GoTo _noerror1
:: Echo the command and the error to the %temp%\tmp}3{.txt file
>%temp%\tmp}3{.txt Echo ==============================
>>%temp%\tmp}3{.txt Echo This command -- %xcopycmd% "%source1%" "%Destination%" -- caused this error:
>>%temp%\tmp}3{.txt Type %temp%\tmp}2{.txt
>>%temp%\tmp}3{.txt Echo It's output was:
>>%temp%\tmp}3{.txt Type %temp%\tmp}1{.txt
>>%temp%\tmp}3{.txt Echo ==============================
Del %temp%\tmp}1{.txt
Ren %temp%\tmp}3{.txt tmp}1{.txt
:_noerror1
[COLOR=Red] :: Add output of the command (and errors if any) to the log file
>>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt[/COLOR]
echo Backing up firefox profiles...
%xcopycmd% "%source2%" "%Destination%\firefox\" 1>%temp%\tmp}1{.txt 2>%temp%\tmp}2{.txt
If %ERRORLEVEL% == 0 GoTo _noerror2
:: Echo the command and the error to the %temp%\tmp}3{.txt file
>%temp%\tmp}3{.txt Echo ==============================
>>%temp%\tmp}3{.txt Echo This command -- %xcopycmd% "%source2%" "%Destination%\firefox" -- caused this error:
>>%temp%\tmp}3{.txt Type %temp%\tmp}2{.txt
>>%temp%\tmp}3{.txt Echo It's output was:
>>%temp%\tmp}3{.txt Type %temp%\tmp}1{.txt
>>%temp%\tmp}3{.txt Echo ==============================
Del %temp%\tmp}1{.txt
Ren %temp%\tmp}3{.txt tmp}1{.txt
:_noerror2
:: Add output of the command (and errors if any) to the log file
>>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt
>>%temp%\tmp}0{.txt Echo ==============================
>>%temp%\tmp}0{.txt Echo Backup Job on %Computername% for %Username%
>>%temp%\tmp}0{.txt Echo Completed on %date% at %time%
>>%temp%\tmp}0{.txt Echo ==============================
copy %temp%\tmp}0{.txt c:\Backups\TmpBackup.log
echo Backup complete!

:: delete all tmp files
Del /q %temp%\tmp}?{.txt


::Originally coded by JStergis
::Modified by New Tech Guy

Jerry


----------



## TheOutcaste

new tech guy said:


> Another question for you as well, when i write this code, should I write the log for every line with action, just so i know if anything breaks down or just keep it to the copy lines? I was thinking of doing everything so i know if any line anywhere blows up for some reason but it may not be needed or necessary.


You can call the file like this:
Backup 2>errlog.txt
any errors from commands that do NOT have STDERR redirected will end up here. It will only be the error message though, and not include the command.
But at least you would know that there was an error
The file will always be created, but if there are no errors, it will have a length of zero. You could check that and if it's not zero copy the error to the main log and create a file on the server you would check to see if an error occurred.

A trick you can use is to use variables for the redirection and errorlevel check for commands you don't need to log on a regular basis. These variables would be set depending on the value of a debug variable, which can be set in the file or directly in the command prompt. With Debug set to 0, they won't be redirected. Set Debug to 1 and they will.
You'd definitely want to use a subroutine to output the error log info rather than having the same echo commands for each command in the file.
In that case you could use this:


Code:


Set debug=1
If [%debug%]==[0] (
    set debugf=9999
    set redir=
    ) Else (
    Set debugf=0
    Set redir=1^>%temp%\tmp}1{.txt 2^>%temp%\tmp}2{.txt
    )


Then use this

rename %Destination%2 backup3 %redir%
If NOT %Errorlevel%==%debugf% Call:debugerror "rename %Destination%2 backup3"
rename %Destination%1 backup2 %redir%
If NOT %Errorlevel%==%debugf% Call:debugerror "rename %Destination%1 backup2"
.
.
.
%xcopycmd% "%source1%" "%Destination%" 1>%temp%\tmp}1{.txt 2>%temp%\tmp}2{.txt
If NOT %ERRORLEVEL%==0 Call:errorsubroutine "%xcopycmd% "%source1%" "%Destination%""
:: Add output of the command (and errors if any) to the log file
>>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt
echo Backing up firefox profiles...
%xcopycmd% "%source2%" "%Destination%\firefox" 1>%temp%\tmp}1{.txt 2>%temp%\tmp}2{.txt
If NOT %ERRORLEVEL% ==0 Call:errorsubroutine "%xcopycmd% "%source2%" "%Destination%\firefox""
:: Add output of the command (and errors if any) to the log file
 >>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt
.
.
.
echo Backup complete!

:: delete all tmp files
Del /q %temp%\tmp}?{.txt
Goto:EOF
:Errorsubroutine
:: Echo the command and the error to the %temp%\tmp}3{.txt file
Set Errtmp=%*
>%temp%\tmp}3{.txt Echo ==============================
>>%temp%\tmp}3{.txt Echo This command -- %Errtmp:~1,-1% -- caused this error:
>>%temp%\tmp}3{.txt Type %temp%\tmp}2{.txt
>>%temp%\tmp}3{.txt Echo It's output was:
>>%temp%\tmp}3{.txt Type %temp%\tmp}1{.txt
>>%temp%\tmp}3{.txt Echo ==============================
Del %temp%\tmp}1{.txt
Ren %temp%\tmp}3{.txt tmp}1{.txt
Goto:EOF
:debugerror
Call:Errorsubroutine %*
:: Add output of the command (and errors if any) to the log file
>>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt
GOTO:EOF

The Rename commands would only be logged when debug is set to 1
the xcopy command will always be logged.

HTH

Jerry


----------



## new tech guy

Ok what i thought of for keeping the logs was to do somthing like you said, have a directory on the hd which holds them temporarily and then at the end moves it to the server on the users directory. Really the server is a NAS and i control it from a pc which has an always on account which acts like an admin center for it (does offsite backup so all user folders are mapped to that server) and i would have the batch copy the text file to it. This is more secure than an open directory everyone can see. This way they can only see their own profile which they are already logged onto. I am starting to work on a batch for my vista account as well. Only problem i have is that i cant write text files to the root directory of the drive and make a folder as vista would have a hissy fit and ask for admin privledges. XP does not mind but vista does not like the idea of changes being made to it, especially by scripts. But yes im thinking of making cleanup scripts for the machines so that the batches are cleaned up after running.


----------



## TheOutcaste

While you can't create files in the root, you should be able to make a folder in the root from a batch file, even as a Standard User, unless the permissions have been modified from the default.

Jerry


----------



## new tech guy

I also had a code request....sort of. I was wondering if you could provide me code for the log files so that if for some reason the log upload fails, it does not delete the log file, instead it keeps the local copy. Also it would need a cleanup for its next run so it cleans out the old file before building a new one. Also, im not going to put the logon command into log because it has a password, instead label it with echo lines and give the stdout and stderr.


----------



## new tech guy

Hi Jerry,
Wrote some code but cannot get it working for some reason, just kinda pukes out with all kinds of crazy errors. Here is the code that i wrote:



Code:


@echo off
echo =======================NeMiSyS Filebackup Utility v5.0==========================
echo Backup starting... >>C:\backup\log.txt
echo Logging into Server...
echo If Exist G:\ net use G: /d >>C:\backup\log.txt
If Exist G:\ net use G: /d 1>>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
echo If Exist H:\ net use H: /d >>C:\backup\log.txt
If Exist H:\ net use H: /d 1>>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
echo Server logon command output for G and H mapping >>G:\logs\laptop\log.txt
net use G: \\mybookworld\vincent /USER:vincent XXXXXXXX>>G:\logs\laptop\log.txt
net use H: \\mybookworld\public >>G:\logs\laptop\log.txt
echo Setting up server directories, if no entries appear in this area, the commands completed without any errors >>C:\backup\log.txt
echo Modifying backup directories...
rmdir G:\laptop_backup\backup3 /s /q >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
rename G:\laptop_backup\backup2 backup3 >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
rename G:\laptop_backup\backup1 backup2 >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
rename G:\laptop_backup\backup backup1 >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
mkdir G:\laptop_backup\backup 1>>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
mkdir G:\laptop_backup\backup\firefox >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
echo NOW the system atcually backs up the files, or does it? heh heh... >>G:\logs\laptop\log.txt
echo Backing up files...
echo xcopy %userprofile% "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt >>C:\backup\log.txt
xcopy %userprofile% "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
echo Now we back up firefox... >>C:\backup\log.txt
echo Backing up firefox profiles...
echo xcopy %appdata&\Mozilla\firefox\profiles "G:\laptop_backup\backup\firefox\" /e /q /c >>C:\backup\log.txt
xcopy %appdata&\Mozilla\firefox\profiles "G:\laptop_backup\backup\firefox\" /e /q /c >>C:\backup\log.txt 2>C:\backup\error.txt
type C:\backup\error.txt>>C:\backup\log.txt
echo Backup complete!
echo Cleaning up... >>C:\backup\log.txt
echo Cleaning up...
pause
If Exist C:\backup\*.bat del C:\backup\*.bat 1>>C:\backup\log.txt 2>C:\backup\error.txt
del C:\backup\error.txt
copy C:\backup\log.bat G:\
exit

I cant understand why it fails, it does not even map the directory right, if you want i can give the log output.


----------



## new tech guy

Ok i found the problem, i mistyped a few log commands in the beginning . I still get a bunch of errors on the window however, not sure why comes up twice on file, once on path.


----------



## TheOutcaste

I'm guessing the lines in green are the typos you found?
It's the little stuff like that, and hitting & for % (which I've been doing all day) that will drive ya nuts


new tech guy said:


> Code:
> 
> 
> @echo off
> echo =======================NeMiSyS Filebackup Utility v5.0==========================
> echo Backup starting... >>C:\backup\log.txt
> echo Logging into Server...
> echo If Exist G:\ net use G: /d >>C:\backup\log.txt
> If Exist G:\ net use G: /d 1>>C:\backup\log.txt 2>C:\backup\error.txt
> [COLOR=Blue]The IF Command itself can't be redirected, as the only error it can cause is a syntax error.
> The redirection applies only to the command if it gets executed[/COLOR][B][COLOR=Red]
> type C:\backup\error.txt>>C:\backup\log.txt
> [/COLOR][COLOR=Blue]Use If EXIST C:\backup\error.txt type C:\backup\error.txt>>C:\backup\log.txt [/COLOR][/B]
> echo If Exist H:\ net use H: /d >>C:\backup\log.txt
> If Exist H:\ net use H: /d 1>>C:\backup\log.txt 2>C:\backup\error.txt
> [B][COLOR=Red] type C:\backup\error.txt>>C:\backup\log.txt
> [/COLOR][/B][B][COLOR=Blue]Use If EXIST C:\backup\error.txt type C:\backup\error.txt>>C:\backup\log.txt [/COLOR][/B]
> echo Server logon command output for G and H mapping >>[COLOR=Red][B][COLOR=SeaGreen]G:\logs\laptop\log.txt[/COLOR]
> [/B][/COLOR][COLOR=Blue][B]Should be C:\backup\log.txt[/B][/COLOR]
> net use G: \\mybookworld\vincent /USER:vincent XXXXXXX >>[COLOR=Red][B][COLOR=SeaGreen]G:\logs\laptop\log.txt[/COLOR]
> [/B][/COLOR][COLOR=Blue][B]Should be C:\backup\log.txt[/B][/COLOR]
> net use H: \\mybookworld\public >>[COLOR=Red][B][COLOR=SeaGreen]G:\logs\laptop\log.txt[/COLOR][/B][/COLOR]
> [B][COLOR=Blue]Should be C:\backup\log.txt[/COLOR][/B]
> echo Setting up server directories, if no entries appear in this area, the commands completed without any errors >>C:\backup\log.txt
> echo Modifying backup directories...
> rmdir G:\laptop_backup\backup3 /s /q >>C:\backup\log.txt 2>C:\backup\error.txt
> type C:\backup\error.txt>>C:\backup\log.txt
> rename G:\laptop_backup\backup2 backup3 >>C:\backup\log.txt 2>C:\backup\error.txt
> type C:\backup\error.txt>>C:\backup\log.txt
> rename G:\laptop_backup\backup1 backup2 >>C:\backup\log.txt 2>C:\backup\error.txt
> type C:\backup\error.txt>>C:\backup\log.txt
> rename G:\laptop_backup\backup backup1 >>C:\backup\log.txt 2>C:\backup\error.txt
> type C:\backup\error.txt>>C:\backup\log.txt
> mkdir G:\laptop_backup\backup 1>>C:\backup\log.txt 2>C:\backup\error.txt
> type C:\backup\error.txt>>C:\backup\log.txt
> mkdir G:\laptop_backup\backup\firefox >>C:\backup\log.txt 2>C:\backup\error.txt
> type C:\backup\error.txt>>C:\backup\log.txt
> echo NOW the system atcually backs up the files, or does it? heh heh... >>[COLOR=Red][B][COLOR=SeaGreen]G:\logs\laptop\log.txt[/COLOR]
> [/B][/COLOR][COLOR=Blue][B]Should be C:\backup\log.txt[/B][/COLOR]
> echo Backing up files...
> echo xcopy %userprofile% "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt >>C:\backup\log.txt
> xcopy [COLOR=Red][B]"[/B][/COLOR]%userprofile%[COLOR=Red][B]"[/B][/COLOR] "G:\laptop_backup\backup\" /e /q /c /EXCLUDE:C:\backup\skipme.txt >>C:\backup\log.txt 2>C:\backup\error.txt
> type C:\backup\error.txt>>C:\backup\log.txt
> echo Now we back up firefox... >>C:\backup\log.txt
> echo Backing up firefox profiles...
> echo xcopy [COLOR=Red][B]"[/B][/COLOR]%appdata[B][COLOR=Red]&[/COLOR][/B]\Mozilla\firefox\profiles[COLOR=Red][B]"[/B][/COLOR] "G:\laptop_backup\backup\firefox\" /e /q /c >>C:\backup\log.txt
> xcopy [COLOR=Red][B]"[/B][/COLOR]%appdata[B][COLOR=Red]&[/COLOR][/B]\Mozilla\firefox\profiles[COLOR=Red][B]"[/B][/COLOR] "G:\laptop_backup\backup\firefox\" /e /q /c >>C:\backup\log.txt 2>C:\backup\error.txt
> [COLOR=Blue][B]Should be %, will cause File Not found to be put in log by next command
> Also, quotes are missing, the space in Documents and Setting or a username will cause errors
> [/B][/COLOR] type C:\backup\error.txt>>C:\backup\log.txt
> echo Backup complete!
> echo Cleaning up... >>C:\backup\log.txt
> echo Cleaning up...
> pause
> If Exist C:\backup\*.bat del C:\backup\*.bat 1>>C:\backup\log.txt 2>C:\backup\error.txt
> del C:\backup\error.txt
> [COLOR=Blue][B]Missing line -- any error from the copy command will not be saved
> type c:\Test1\backup\error.txt>>c:\Test1\backup\log.txt[/B][/COLOR]
> copy C:\backup\log.[B][COLOR=Red]bat[/COLOR][/B] G:\
> [COLOR=Blue][B]Should be txt[/B][/COLOR]
> exit


This copies the log to the root folder instead of appending it, so you will only have a log for the last backup.
I'd suggest putting the log into G:\laptop_backup\backup\ so you will have the log for each of the 3 backups. I would also copy the user profile to G:\laptop_backup\backup\profile.

Since you are not using the H switch with xcopy, hidden files will not be copied. If the users systems are set to not show hidden/system files, the Application Data and Local Settings trees will not be copied. Since you are copying firefox separately I'm guessing that's how it's setup.
Couple of things -- If you are depending on hidden files not being copied, make sure the user can't change that setting. Or make sure the exclude file covers everything, even hidden folders.
If you use Outlook or Outlook Express, they do store their data in those trees unless you've changed the path(at least on XP, not sure about Outlook or Windows Mail on Vista), so if your users use either, you may want to add commands to specifically back them up as well.

Jerry


----------



## new tech guy

Yeah i have been making silly typos in the code, i was picking off lines cause i had class the next day before putting the code down for a bit. My main thing was later during the night yesterday was to just get the main backup running again so at least schoolwork would be saved. As for hidden files/system, i dont back those up. All users of the house are on outlook and i moved the .pst files to the contacts folder so that they are right in the scripts path. I actually did that when i first wrote this thing so emails are fine. As far as i understand outlook, pretty much everything is saved in there although i never saw account settings anywhere, gotta look for a way to output a file of that too to simplify an outlook restore. Right now for that when i first set up a pc, i set up outlook then image it. It then copies the .pst files and if a restore is done, all i need to do is switch the pst in the system from time of image (it was already moved and everything in the image) with one from the script output. I stopped working on the code last night because as you said it was making me a little crazy and i just had to step away from it for a bit after getting mine to work (albeit buggy but actual backups work). I will look at what you gave me and give it a try, now if i understand correctly the code you gave me will work for all users, just need to change usernames and some paths possibly?


----------



## new tech guy

Sorry i have not done much in terms of the script lately. Its been because ive been busy during the week between school and work, will start working on it again as soon as i have some free time.


----------



## new tech guy

Ok i just ran the script you posted in post 6. Worked fine on vista with no errors just have one question, where did the log go? I looked in C:\backup but dont see anything anything in it. Where is the log at?


----------



## TheOutcaste

Looks like I specified *C:\Backups* instead of *C:\Backup* in the copy command near the end:
copy %temp%\tmp}0{.txt c:\Backups\TmpBackup.log

If the Destination folder doesn't exist, Copy won't copy the file. Get rid of the* s* and the Log should copy fine, named TmpBackup.log.

Been slowly putting together a couple of subroutines to do the type of logging you are doing by using self-modifying code.
Logging will be based on a command line switch to set the "verbose" level:
0. All output and errors to the screen
1. Output to screen; If an error occurs, output the command and the error to a log
2. All commands, their output, and errors if any to a log

Of course any commands can be set to always use one of the above levels regardless of the switch, or to always send their output to the log. This could also be controlled by another switch.

Hope to make it easy to add to any file simply by adding a variable to the start of each line you want to log in a file, then tacking on the subroutines.

One of those spare time projects life keeps interrupting.

Jerry


----------



## new tech guy

Ok thanks alot, by the way i will put a cred in for ya at the end when this is done . Right now its not there because were still working on it, once its stable n all i will add one.


----------



## new tech guy

yup, did exactly what you said, i changed the backups to backup and it worked. Now i need to figure out a way to save them on the server, i could simply copy the text file to a folder on each user's directory as then i can just review them from the server device. I was going to create a directory on the server to save these files in there and somehow append somthing to clear it at each run. Also mine had no errors so it just shows output of the text file in the logs so i assume the errors will show if any occur. I have to play around with it and then will be modifying it for the other machines in the house and with our variable use the changes should be minimal.


----------



## new tech guy

Hi Jerry,
Thank you for the help so far. Today i took the time to impliment the new system into the network, a couple accounts havent been tested yet but i will just stay tuned for the logs to see what they bring and i will fix things as they go,

Anyways, just a final question, one of my machines (happens to be the xp one) does not have firefox installed on it so therefore i took out the firefox code. Just want to make sure i got everything and didnt break anything important. Test running seems ok but just to be sure i am posting mom's version of the code. I have a similar version on my account on that pc (which is my offsite server account) and well, here is the code:



Code:


@echo off
echo ====================NeMiSyS Filebackup Utility v5.0=============================
Set source1=%Userprofile%
Set Destination=G:\mom_desktop\backup
Set xcopycmd=xcopy /ceq /EXCLUDE:C:\backup_program\mom\skipme.txt
echo Logging into Server...
If Exist G:\ net use G: /d /y
If Exist H:\ net use H: /d /y
net use G: \\mybookworld\barb /USER:desktopmom XXXXXXXXXXX
net use H: \\mybookworld\public
echo Modifying backup directories...
rmdir %Destination%3 /s /q
rename %Destination%2 backup3
rename %Destination%1 backup2
rename %Destination% backup1
mkdir %Destination%
echo Backing up files...
>%temp%\tmp}0{.txt Echo ==============================
>>%temp%\tmp}0{.txt Echo Backup Job on %Computername% for %Username%
>>%temp%\tmp}0{.txt Echo Started on %date% at %time%
>>%temp%\tmp}0{.txt Echo ==============================
%xcopycmd% "%source1%" "%Destination%" 1>%temp%\tmp}1{.txt 2>%temp%\tmp}2{.txt
If %ERRORLEVEL% == 0 GoTo _noerror1
:: Echo the command and the error to the %temp%\tmp}3{.txt file
>%temp%\tmp}3{.txt Echo ==============================
>>%temp%\tmp}3{.txt Echo This command -- %xcopycmd% "%source1%" "%Destination%" -- caused this error:
>>%temp%\tmp}3{.txt Type %temp%\tmp}2{.txt
>>%temp%\tmp}3{.txt Echo It's output was:
>>%temp%\tmp}3{.txt Type %temp%\tmp}1{.txt
>>%temp%\tmp}3{.txt Echo ==============================
Del %temp%\tmp}1{.txt
Ren %temp%\tmp}3{.txt tmp}1{.txt
:_noerror1
 :: Add output of the command (and errors if any) to the log file
>>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt
:_noerror2
:: Add output of the command (and errors if any) to the log file
>>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt
>>%temp%\tmp}0{.txt Echo ==============================
>>%temp%\tmp}0{.txt Echo Backup Job on %Computername% for %Username%
>>%temp%\tmp}0{.txt Echo Completed on %date% at %time%
>>%temp%\tmp}0{.txt Echo ==============================
copy %temp%\tmp}0{.txt c:\backup_program\mom\TmpBackup.log
copy C:\backup_program\mom\*.log G:\logs\desktop /y
echo Backup complete!

:: delete all tmp files
Del /q %temp%\tmp}?{.txt


::Originally coded by JStergis
::Modified by New Tech Guy
::Further help and logging capabilities added by Jerry aka: TheOutCaste


----------



## TheOutcaste

Sorry for the delay, been more than a bit under the weather.



Code:


:_noerror1
 :: Add output of the command (and errors if any) to the log file
>>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt
[COLOR=Red]:_noerror2
:: Add output of the command (and errors if any) to the log file
>>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt[/COLOR]
>>%temp%\tmp}0{.txt Echo ==============================

You can delete the part in red. That section was to add the output of the Firefox profile copy. In this case it will cause duplicate entries for the output of the command that copies the user profile.

Some random thoughts:

The log file will be overwritten every time this is run. If you want to keep a history, you'd need to copy the permanent log off of the server, then append the TmpBackup.log file to it, then write the permanent log back. You'd need to archive this occasionally to keep the size down. If you only want to keep the log for each backup, make a log folder at *%Destination%\log* (in this case that would be G:\mom_desktop\backup\log). Then the log will be deleted when the backup is deleted.

Removing the #3 backup folder should be done _after_ the backup is complete. A power failure would leave the current backup incomplete, and the 3rd version would have been deleted. Or, if the user presses CTRL+C and stops the backup, then repeats that a few times, they would delete all their backups. Making a backup4, then delete it only if successful would solve that. Then you just check if backup4 exists; if it does, you can either refuse to backup until it's manually deleted, or delete the failed backup folder and try again. I've changed it to the latter in the code below.

Also added a variable to set the number of backup versions to keep, and use a For loop to do the renaming. This way you can change the number without having to add or remove Rename statements. If you decrease the number, you'll have to manually remove the older versions you no longer want to keep, though you could add code to do that automatically as well.
This also lets you run it on a new system without the rename commands giving errors until you have the correct number of backups created.

Also been thinking about the Net Use command and various issues I've seen in the past.

When you want to use a drive letter mapped to a share, you can have 4 possibilities:


Drive letter is not mapped
Drive letter is mapped, but possibly to a different share
Drive letter is assigned to hardware (Card Reader, USB Drive, MP3 player, etc)
Share is mapped to a different drive letter
Some solutions:

Map to correct share
If the share requires a password, it needs to be coded in the file, or you must prompt the user for it.***
Delete it and map to correct share
Two problems:
If you don't restore the user's mapping you could have unforseen problems
example, user deletes everything in what he thinks is his share.
Ends up deleting everything in his user folder instead
If the share requires a password, it needs to be coded in the file, or you must prompt the user for it.***
If it's already mapped to the correct share just use it, then no problems with a password

Only option is to use a different letter
Two options:
Create a map to the drive letter you want
Same issue with password if it exists
Use the existing drive letter, no problems with a password

***For WinXP and Vista, you can use the */SAVECRED* switch to save the password in the users profile. Windows will provide the saved User name and password whenever an attempt is made to map to that share. This means you only need to use *Net Use G: \\mybookworld\barb* in the batch file. On each system, you would have to run the following command ONCE for each user:
*net use g: \\sharename /SAVECRED* (drive letter doesn't matter)
You'll be prompted for the user name and password, enter them, then when it connects, the credentials will be saved. The credentials are encrypted and stored in the Credentials Manager, same with any other Saved Windows passwords -- there are ways to read it, but not as easy as a plain text password in a batch file. Anytime the user changes the password, you would have to run the */SAVECRED* command again to save the new info.

I've written a subroutine that will check to see if a share is already mapped. If so, it returns the drive letter. If not, it will map the share to the next available drive letter, then return the drive letter that was assigned. You can specify a user name and password if you want, or prompt the user for the password.
It logs the results or errors to the log file (if it actually has to create the map, it simulates successful output. This way, password prompts will still appear on screen)
So, adding all the above gives the following. The user name and password (in blue) don't need to be included if you use the */SAVECRED* switch to save the credentials. The line in red would need to be added after the xcopy command for the Firefox profile on the other PCs, as well as something similar for any commands whose failure is serious enough that you would want to redo the backup.



Code:


@Echo off
Echo ====================NeMiSyS Filebackup Utility v5.0=============================
Set source1=%Userprofile%
Set xcopycmd=xcopy /ceq /EXCLUDE:C:\backup_program\mom\skipme.txt
Set _NumVersions=4
Set _ErrFlag=0
Echo Logging into Server...
Call :_MapChk "\\mybookworld\barb" _DestDrv _NewDest [COLOR=Blue]desktopmom XXXXXX[/COLOR]
If Errorlevel 1 (
  Echo An Error occurred logging into the Server
  Echo Backup Aborted, Please check the log
  Goto :EOF)
Call :_MapChk1 "\\mybookworld\public" _PublicDrv _NewPublic
If Errorlevel 1 (
  Echo An Error occurred logging into the Server
  Echo Backup Aborted, Please check the log
  Goto :EOF)
Set Destination=%_DestDrv%\mom_desktop\backup
Echo Modifying backup directories...
Set _ErrFlag=0
If EXIST %Destination%%_NumVersions% (
  RmDir /q /s %Destination%
  Goto _MakeNew
  )
Setlocal EnableDelayedExpansion
For /L %%I In (%_NumVersions%,-1,2) Do (
  Set /A _VNum=%%I-1
  If EXIST %Destination%!_VNum! Rename %Destination%!_VNum! backup%%I
  )
Rename %Destination% backup1
:_MakeNew
MkDir %Destination%
Endlocal
Echo Backing up files...
>%temp%\tmp}0{.txt Echo ==============================
>>%temp%\tmp}0{.txt Echo Backup Job on %Computername% for %Username%
>>%temp%\tmp}0{.txt Echo Started on %date% at %time%
>>%temp%\tmp}0{.txt Echo ==============================
%xcopycmd% "%source1%" "%Destination%" 1>%temp%\tmp}1{.txt 2>%temp%\tmp}2{.txt
If %ERRORLEVEL% == 0 GoTo _noerror1
:: If an error occurs, set _ErrFlag equal to %ERRORLEVEL%. If it's already been set to a higher number it won't be lowered
:: For XCopy, an ERRORLEVEL of 1 means nothing found to copy, not actually a failure, so only flag 2 and higher
[COLOR=Red]If %ERRORLEVEL% GTR %_ErrFlag% If %ERRORLEVEL% GEQ 2 Set _ErrFlag=%ERRORLEVEL%[/COLOR]
:: Echo the command and the error to the %temp%\tmp}3{.txt file
>%temp%\tmp}3{.txt Echo ==============================
>>%temp%\tmp}3{.txt Echo This command -- %xcopycmd% "%source1%" "%Destination%" -- caused this error:
>>%temp%\tmp}3{.txt Type %temp%\tmp}2{.txt
>>%temp%\tmp}3{.txt Echo It's output was:
>>%temp%\tmp}3{.txt Type %temp%\tmp}1{.txt
>>%temp%\tmp}3{.txt Echo ==============================
Del %temp%\tmp}1{.txt
Ren %temp%\tmp}3{.txt tmp}1{.txt
:_noerror1
 :: Add output of the command (and errors if any) to the log file
>>%temp%\tmp}0{.txt Type %temp%\tmp}1{.txt
>>%temp%\tmp}0{.txt Echo ==============================
>>%temp%\tmp}0{.txt Echo Backup Job on %Computername% for %Username%
>>%temp%\tmp}0{.txt Echo Completed on %date% at %time%
>>%temp%\tmp}0{.txt Echo ==============================
copy %temp%\tmp}0{.txt c:\backup_program\mom\TmpBackup.log
copy C:\backup_program\mom\*.log G:\logs\desktop /y
Echo Backup complete!
:: If no errors, delete the oldest backup folder
If %_ErrFlag%==0 RmDir /q /s %Destination%%_NumVersions%
:: delete all tmp files
Del /q %temp%\tmp}?{.txt
Goto:eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::                    Subroutines
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:_MapChk
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Usage Call :_MapChk "path"  retv newflag [username password]
::          "path" Share to be mapped. Must be in quotes
::          retv    This variable will be set to the mapped drive letter
::          newflag Set to 0 if drive already mapped, 1 if a drive was mapped
::       username Username to be used. Enter * if you wish to use currently logged on user
::       password Password to use. Enter * if you wish to be prompted
:: Check if the share "path" is already mapped. If so, use the current letter
:: If not, map the share to the next available letter. The drive letter 
:: will be returned in the variable specified by retv
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Setlocal EnableDelayedExpansion
If [%3]=[] Goto _Pchk1
Set _User=
If %3==* Goto _Pchk1
Set _User=/user:%3
:_Pchk1
Set _Pass=
If NOT [%4]==[] Set _Pass=%4
Set _t1=%~1
For /L %%I In (5,1,26) Do If NOT "!_t1:~%%I,1!"=="" Set _len=%%I
If !_len! LEQ 24 (
:: Pad with 20 trailing spaces and a period
  Set _t1=!_t1!                    .
  Set _t1=!_t1:~0,25!
  )
:: Add one trailing space and a period
Set _t1=!_t1! .
:: Trim off period
Set _t1=!_t1:~0,-1!
Set _Flag=0
:_MapChk1
For /F "Tokens=2*" %%I In ('net use ^|Find /I %1') Do (
 Set _Found=%%J
 Set _Found=!_Found:Microsoft Windows Network=!
 If /I !_Found!==!_t1! Set _PDrv=%%~dI
 )
If NOT [%_PDrv%]==[] EndLocal&Set %2=%_PDrv%&Set %3=%_Flag%&Goto :EOF
Set _Flag=1
Net Use * %_Pdrv% %1 %_User% %_Pass%
If NOT Errorlevel 1 Goto _MapChk1
EndLocal&Goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Originally coded by JStergis
::Modified by New Tech Guy
::Further help and logging capabilities added by Jerry aka: TheOutCaste

Jerry


----------



## new tech guy

Sorry about slow response jerry, tied up with school/work during the week and allot of stuff at home was on hold as well. However, i do want to do what you stated with the batch pretaining to the net use. As for the file backups, i dont think i filled you in yet on the fact that there is a offsite backup i use as well where i send the regular backups to nightly. Right now it is a slimmed down version of the regular backups but because of its ability to go 30 versions back and an abundance of disk space i have for it i am going to tweak it to back up the entire backup folder of the newest backup. That plus 30 version history on offsite should have me covered i believe. Also i chose g and h for directories as i know they are a little further down in the list of drive letters and leave a couple slots open for usb devices. Been using them on g/h config for a bit without any trouble yet. If i do run into trouble i could always just make an edit to use a further down drive letter. However, i do like the idea of using the savecred switch. Will have to play with it as it could amplify security. Also it is fine to overwrite log files on execute, that whole backup folder is cleared by the initialization batch which has the purpose of making sure the system is using the latest version of the utility.


----------



## new tech guy

Hello Jerry,
I just played with the password suggestion a bit, got it working on xp, not vista. At this point, i beleive i am going to just leave it as is. I hope you understand. I am fixing the log as you instructed for the non-firefox machine. Im sorry to make you go through the extra work. I am keeping logs however and that part is working B-E-A-utilifly. Thanks again and i am marking the thread solved :up:

PS: I just thought that with the password security, yes i could fix it but now that everything else works i just feel as if im reinventing the wheel.


----------



## TheOutcaste

Just noticed an error in the MapChk routine I posted. Seems I have two versions, one I named.bat that has errors, then a working one named .cmd. I posted the none working version.

The corrected section of code is as follows:


Code:


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Setlocal EnableDelayedExpansion
If [%[COLOR=Red]4[/COLOR]]=[COLOR=Red]=[/COLOR][] Goto _Pchk1
Set _User=
If %[COLOR=Red]4[/COLOR]==* Goto _Pchk1
Set _User=/user:%[COLOR=Red]4[/COLOR]
:_Pchk1
Set _Pass=
If NOT [%[COLOR=Red]5[/COLOR]]==[] Set _Pass=%[COLOR=Red]5[/COLOR]
Set _t1=%~1

Jerry


----------

