Anthony Key
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_1 5\O1_MF_S_ 761887550_ 773B3ZGP_. BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_15 \O1_MF_ANN NN_TAG2011 0915T03245 1_773B262J _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_15 \O1_MF_ANN NN_TAG2011 0915T03245 1_773B26WD _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_15 \O1_MF_NNN DF_TAG2011 0915T03001 9_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$\devo rasisgtid\ rman\logs\ Xcopy_rman _backup_%d ate:~4,2%% date:~7,2% %date:~10, 4%.txt"
if %errorlevel% EQU 1 (D:\adminscripts\common\bl at262\full \blat -to EMail1y@domain -subject "XCOPY
of RMAN Online Backup of DSISGTD was Successful" -bodyf
\\dbstor\oraclebkup$\devor asisgtid\r man\logs\X copy_rman_ backup_%da te:~4,2%%d ate:~7,2%% date:~10,4 %.txt
) else (D:\adminscripts\common\bl at262\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$\devor asisgtid\r man\logs\X copy_rman_ backup_%da te:~4,2%%d ate:~7,2%% date:~10,4 %.txt
)
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
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
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$\devo
if %errorlevel% EQU 1 (D:\adminscripts\common\bl
of RMAN Online Backup of DSISGTD was Successful" -bodyf
\\dbstor\oraclebkup$\devor
) else (D:\adminscripts\common\bl
Backup of DSISGTD Failed,so please restart XCOPY before next weekly backup" -bodyf
\\dbstor\oraclebkup$\devor
)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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%"
)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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_2 6\O1_MF_S_ 762837839_ 780B4JKY_. BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_ANN NN_TAG2011 0926T03225 6_780B2M39 _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_ANN NN_TAG2011 0926T03225 6_780B2MV7 _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_ANN NN_TAG2011 0926T03225 6_780B4D48 _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_NNN DF_TAG2011 0926T03001 4_7808R039 _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_NNN DF_TAG2011 0926T03001 4_7808R1JY _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_NNN DF_TAG2011 0926T03001 4_78096WGJ _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_NNN DF_TAG2011 0926T03001 4_7809SHY4 _.BKP
X:\rman\DSISGTD\logs\rman_ backup_hot _full_10g_ DSISGTD_09 262011.log
X:\rman\DSISGTD\temp\rman_ backup_hot _full_10g_ DSISGTD_09 262011.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_2 6\O1_MF_S_ 762837839_ 780B4JKY_. BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_ANN NN_TAG2011 0926T03225 6_780B2M39 _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_ANN NN_TAG2011 0926T03225 6_780B2MV7 _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_ANN NN_TAG2011 0926T03225 6_780B4D48 _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_NNN DF_TAG2011 0926T03001 4_7808R039 _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_NNN DF_TAG2011 0926T03001 4_7808R1JY _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_NNN DF_TAG2011 0926T03001 4_78096WGJ _.BKP
X:\rman\DSISGTD\BACKUPSET\ 2011_09_26 \O1_MF_NNN DF_TAG2011 0926T03001 4_7809SHY4 _.BKP
X:\rman\DSISGTD\logs\rman_ backup_hot _full_10g_ DSISGTD_09 262011.log
X:\rman\DSISGTD\temp\rman_ backup_hot _full_10g_ DSISGTD_09 262011.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..
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
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\logs\rman_
X:\rman\DSISGTD\temp\rman_
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
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\BACKUPSET\
X:\rman\DSISGTD\logs\rman_
X:\rman\DSISGTD\temp\rman_
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..
ASKER
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
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
Steve
ASKER
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
Thanks,
7Souls
ASKER
Hi dragon-it,
Do you want me to keep the set log line with a quote around the file name?
set log="\\dbstor\oraclebkup$\ devorasisg tid\rman\l ogs\Xcopy_ rman_backu p_%date:~4 ,2%%date:~ 7,2%%date: ~10,4%.txt "
Do you want me to keep the set log line with a quote around the file name?
set log="\\dbstor\oraclebkup$\
ASKER
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
Thanks,
7Souls
ASKER
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
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
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
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
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
~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
~bp
ASKER
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
So thanks again you've been a big help. Now all I need to do is buy a good Windows scripting book.
7Souls
set log="\\dbstor\oraclebkup$\
set blat=D:\adminscripts\commo
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%
)
)