Link to home
Start Free TrialLog in
Avatar of Anthony Key
Anthony KeyFlag for United States of America

asked on

New Question but linked to ID: 27307588 using the Findstr logic

Hi,
 This is a new issue based on the question and solution given in ID: 27307588. I'm still having problems with my xcopy and trying to figure out the approach on my logic that I'm currently using. Currently I'm looking at the xcopy log file and if the Findstr finds a '0 File(s) copied' then I send an email stating that the copy didn't do anything and to look into the problem. Now what I need is some logic tied to this which evaluates whether there is a 'File(s) copied' string in the xcopy log file.

Example:
After last nights xcopy I got:

Xcopy started on Thu 09/15/2011 at 03:26:02  
 
X:\rman\DSISGTD\AUTOBACKUP\2011_09_15\O1_MF_S_761887550_773B3ZGP_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_15\O1_MF_ANNNN_TAG20110915T032451_773B262J_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_15\O1_MF_ANNNN_TAG20110915T032451_773B26WD_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_15\O1_MF_NNNDF_TAG20110915T030019_7738N52S_.BKP
 
Xcopy ended on Thu 09/15/2011 at 03:39:18

I got some files copied but not all of them and I got no '# File(s) copied' string in the logfile and my logic sent an email out stating that the copy was successful. Below is the current logic. Problem if I add a separate findstr evaluation then it will fall through to the next findstr and send out two separate but different email messages.

Can findstr evaluate using an 'or'? Do you see my problem?
Thanks,
7Souls

findstr /i /r /c:"^ *0 File(s) copied"
"\\dbstor\oraclebkup$\devorasisgtid\rman\logs\Xcopy_rman_backup_%date:~4,2%%date:~7,2%%date:~10,4%.txt"
if %errorlevel% EQU 1 (D:\adminscripts\common\blat262\full\blat -to EMail1y@domain -subject "XCOPY

of RMAN Online Backup of DSISGTD was Successful" -bodyf

\\dbstor\oraclebkup$\devorasisgtid\rman\logs\Xcopy_rman_backup_%date:~4,2%%date:~7,2%%date:~10,4%.txt
) else (D:\adminscripts\common\blat262\full\blat -to EMail1y@domain  -subject "XCOPY of RMAN Online

Backup of DSISGTD Failed,so please restart XCOPY before next weekly backup" -bodyf

\\dbstor\oraclebkup$\devorasisgtid\rman\logs\Xcopy_rman_backup_%date:~4,2%%date:~7,2%%date:~10,4%.txt
)
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

What about this:

set log="\\dbstor\oraclebkup$\devorasisgtid\rman\logs\Xcopy_rman_backup_%date:~4,2%%date:~7,2%%date:~10,4%.txt"
set blat=D:\adminscripts\common\blat262\full\blat

find /i "File(s) copied" %log%
if errorlevel 1 (
  rem Now File(s) copied has not been found - send failure email
) ELSE (
  rem Check if 0 files
  findstr /i /r /c:"^ *0 File(s) copied" %log%
  if %errorlevel% EQU 1 (
    %blat% -to EMail1y@domain -subject "XCOPY of RMAN Online Backup of DSISGTD was Successful" -bodyf %log%
  ) ELSE (
    %blat% -to EMail1y@domain  -subject "XCOPY of RMAN Online Backup of DSISGTD Failed,so please restart XCOPY before next weekly backup" -bodyf %log%
  )
)
SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Anthony Key

ASKER

All,

It worked thanks you so much. Dragon-it and billprew also BillDL you guys are the best.  I'll hand out the points a bit later there are some things that I have to check right now.                                                                                                                                                                    
Thanks again,
7Souls                                                                                                                  
Glad!

I think I like Bill's script better there anyway, though I think I'd have gone one step further and stuck a variable in for subject too to make it less heavy on those lines and easier to read too... i.e. this is Bill's script with minor amendment... Mine doesn't actually even have the line in to send an email if there is not "Files copied" line for some reason, not quite sure why!?

Steve


@echo off

REM Variables to store possibly changeable values and to make main script more readable
REM =============================================================================================================
set log="\\dbstor\oraclebkup$\devorasisgtid\rman\logs\Xcopy_rman_backup_%date:~4,2%%date:~7,2%%date:~10,4%.txt"
set blat=D:\adminscripts\common\blat262\full\blat
set sendto=EMail1y@domain
set SubjectOK="XCOPY of RMAN Online Backup of DSISGTD was Successful"
set SubjectFail="XCOPY of RMAN Online Backup of DSISGTD Failed,so please restart XCOPY before next weekly backup"
REM =============================================================================================================

set success=N  
find /i "File(s) copied" "%log%" >NUL && (findstr /i /r /c:"^ *0 File(s) copied" "%log%" >NUL || set success=Y)  

if %success% == Y (  
  ECHO "%blat%" -to %sendto% -subject %SubjectOK% -bodyf "%log%"  
) else (  
  ECHO "%blat%" -to %sendto% -subject %SubjectFail% -bodyf "%log%"  
)

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi dragon-it,

I testing the last bit of code that you sent me and what I have is two different set of results. When I ran it against the xcopy log file that looked like this (See below) it stated that the copy was successful.
When I ran it again and the copy was successful but the subject stated that it was not successful. Any thoughts.

Copy was successful both times the first time the subject stated success:

Xcopy started on Mon 09/26/2011 at 08:45:28  
 
X:\rman\DSISGTD\AUTOBACKUP\2011_09_26\O1_MF_S_762837839_780B4JKY_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_ANNNN_TAG20110926T032256_780B2M39_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_ANNNN_TAG20110926T032256_780B2MV7_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_ANNNN_TAG20110926T032256_780B4D48_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_NNNDF_TAG20110926T030014_7808R039_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_NNNDF_TAG20110926T030014_7808R1JY_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_NNNDF_TAG20110926T030014_78096WGJ_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_NNNDF_TAG20110926T030014_7809SHY4_.BKP
X:\rman\DSISGTD\logs\rman_backup_hot_full_10g_DSISGTD_09262011.log
X:\rman\DSISGTD\temp\rman_backup_hot_full_10g_DSISGTD_09262011.rcv
10 File(s) copied
 
Xcopy ended on Mon 09/26/2011 at 09:45:23

The second time the copy was successful (same amount of files copied) but the subject stated that it wasn't successful.

Xcopy started on Mon 09/26/2011 at 10:06:52  
 
X:\rman\DSISGTD\AUTOBACKUP\2011_09_26\O1_MF_S_762837839_780B4JKY_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_ANNNN_TAG20110926T032256_780B2M39_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_ANNNN_TAG20110926T032256_780B2MV7_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_ANNNN_TAG20110926T032256_780B4D48_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_NNNDF_TAG20110926T030014_7808R039_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_NNNDF_TAG20110926T030014_7808R1JY_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_NNNDF_TAG20110926T030014_78096WGJ_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_26\O1_MF_NNNDF_TAG20110926T030014_7809SHY4_.BKP
X:\rman\DSISGTD\logs\rman_backup_hot_full_10g_DSISGTD_09262011.log
X:\rman\DSISGTD\temp\rman_backup_hot_full_10g_DSISGTD_09262011.rcv
10 File(s) copied
 
Xcopy ended on Mon 09/26/2011 at 11:04:52  

Any thoughts on how I can fix this?

Thanks,
7Souls..


Hi dragon-it,

I think I figured it out the first time that I ran the code I used the @echo off along with "%log%". But the second attempt I executed the code without the @echo off and "%log%" and what I noticed in the log feed back was that a double-double quote was put before and after the logfile name along with the statement sent to the screen 'file not found'. I tested just a simple send with out the "'s around %log% and it worked.

Thanks I'll use the @echo off.

7Souls
yes sorry looks like we have " around set log= line  AND on the blat lines.  just remove them around %log% on the blat line.

Steve
I have quite a few lines with the %log% so should I take them out on both the 'set log' statement and the blat line along with taking out the @echo off. Or can I leave the @echo off and leave the quotes on.

Thanks,
7Souls
Hi dragon-it,
Do you want me to keep the set log line with a quote around the file name?

set log="\\dbstor\oraclebkup$\devorasisgtid\rman\logs\Xcopy_rman_backup_%date:~4,2%%date:~7,2%%date:~10,4%.txt"
Thanks again guys I took the quotes off of %blat% and %log% and the "quotes" from around the set log and let the Windows scheduler run the script. And for the last couple of nights the correct subject line was produced along with correct conditions. So I'll close this for now and assign some points.

Thanks,
7Souls
I have a comment and a question.

Thanks for the collabrative effort with helping me get to this solution. And my question is 'Can someone explain to me what the double  "&" in '>NUL &&' meant?

Again thanks,
7Souls
Avatar of Bill Prew
Bill Prew

The && (and ||) can be used after a command is run to test the exit status of that command and if everything is okay do something, or if there were errors do something else.  && indicates to test and if no errors do something, || means to test and if errors do something.  Some addition info here:

http://www.dostips.com/DtCodeSnippets.php#Snippets.ConditionalExecution

~bp
No problem.  

The > NUL bit is hiding the output of the previous command.

The && (and ||) are useful shortcuts to check the errorlevel of the previous process:

If the process returns an error then the bit after the || runs
If the process does not return an error the bit after the && runs

e.g. for a simple way of testing (I always forget if it is && or || and end up checking this sort of way to make sure!!)

dir c:\ && echo That was the C drive
dir c:\not-there || echo That was an error  - %errorlevel%

hth

You can also do:

dir & dir

and it runs the second command regardless
or
dir | find "xxx"

and it passes the output through pipe to the next command's input.

hth

Steve
I suppose it was silly re-inventing the wheel there while Bill found a better explanation in his link!
Hi Steve, I take a few days off and you've been busy, I need to find you more real work :-).

~bp
Wish I had... is quiet at the moment :-( ... well work is anyway!  Thought you must be hiding, have actually been able to get a few posts in before you'd nabbed it...
Yes, was away for a bit and typically don't try to keep up on EE via mobile etc during those breaks.  Hope all is well with the family, take care Steve.

~bp
No it wasn't silly at all both links helped me to look at the conditions that I was checking for in a simpler and eloquent way.  

So thanks again you've been a big help. Now all I need to do is buy a good Windows scripting book.
7Souls