?
Solved

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

Posted on 2011-09-15
22
Medium Priority
?
500 Views
Last Modified: 2012-05-12
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
)
0
Comment
Question by:7Souls
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
  • 4
  • +1
22 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36552285
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%
  )
)
0
 
LVL 56

Assisted Solution

by:Bill Prew
Bill Prew earned 900 total points
ID: 36552979
Here's how I'd approach it.  I really like Steve's idea of using some variables to make the code cleaner, readable and easier to maintain, gotta go with that. I think it's easiest and clearer to set a variable based on the search results, and then trigger off that for the messaging.

The idea of the success variable is assume the copy failed, and then only if you file the "files(s) copied" and if it wasn't "0 files(s) copied" do we have a successful copy.

@echo off

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 email=EMail1y@domain

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 %email% -subject "XCOPY of RMAN Online Backup of DSISGTD was Successful" -bodyf "%log%"
) else (
  ECHO "%blat%" -to %email% -subject "XCOPY of RMAN Online Backup of DSISGTD Failed, so please restart XCOPY before next weekly backup" -bodyf "%log%"
)

Open in new window

~bp
0
 
LVL 38

Assisted Solution

by:BillDL
BillDL earned 100 total points
ID: 36553109
I know this is a departure to your specific question about parsing the xcopy log, and I don't mean to take away from the exceptional suggestions above that directly address your question here, but have you considered using Robocopy instead of xcopy?

xcopy has a limited set of %errorlevel% returns:
0 = Files were copied without error
1 = No files were found to copy
2 = The user pressed CTRL+C to terminate xcopy
4 = Initialization error occurred. Not enough memory or disk space, or invalid drive name, or invalid syntax on the command line
5 = Disk write error occurred.

robocopy has a more comprehensive set of exit codes to diagnose results to decide whether you should be notified or not:
http://ss64.com/nt/robocopy-exit.html

Just making the suggestion for your further investigation.  No response required and I hope this doesn't side-track your question.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:7Souls
ID: 36593569
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                                                                                                                  
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36594506
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

0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 1000 total points
ID: 36594523
Removing the word ECHO in front of "%BLAT%" of course as with Bill's original to make it send rather than just show the results.... I suppose you could go slightly further too:
@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 =============================================================================================================
REM May be going too far?
set SendSuccess="%blat%" -to %sendto% -subject %SubjectOK% -bodyf "%log%" 
set SendFail="%blat%" -to %sendto% -subject %SubjectFail% -bodyf "%log%"
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 (%SendSuccess%) ELSE (%SendFail%)

Open in new window

0
 

Author Comment

by:7Souls
ID: 36599853
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..


0
 

Author Comment

by:7Souls
ID: 36599928
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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36599992
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
0
 

Author Comment

by:7Souls
ID: 36600111
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
0
 

Author Comment

by:7Souls
ID: 36600476
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"
0
 

Author Comment

by:7Souls
ID: 36716729
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
0
 

Author Closing Comment

by:7Souls
ID: 36716842
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
0
 
LVL 56

Expert Comment

by:Bill Prew
ID: 36716923
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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36716945
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
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36716956
I suppose it was silly re-inventing the wheel there while Bill found a better explanation in his link!
0
 
LVL 56

Expert Comment

by:Bill Prew
ID: 36716977
Hi Steve, I take a few days off and you've been busy, I need to find you more real work :-).

~bp
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36717010
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...
0
 
LVL 56

Expert Comment

by:Bill Prew
ID: 36717049
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
0
 

Author Comment

by:7Souls
ID: 36717648
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
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Introduction to Processes
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question