Solved

Need to use the find command and evaluate if string not found

Posted on 2011-09-14
11
308 Views
Last Modified: 2012-06-27
Hi currently I'm using this logic in a script (See below) however when I recently got '10 Files copied' my logic came up with an "%errorlevel%" = 0 and therefore I emailed the wrong message.
I need to come up with a different error check maybe some thing that states that if 'Files copied' not found then "%errorlevel%" = 0 or 1. How would I do this?

Thanks,
7Souls

find /i "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
  • 4
  • 4
  • 3
11 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 36536682
The problem is that xcopy displays the text "File(s) copied" even if no files are copied, correct?  Otherwise you could just do this:

  find "File(s) copied"  "Xcopy_rman_backup_%date:~4,2%%date:~7,2%%date:~10,4%.txt"
  if %errorlevel% EQU 0 ( echo Files Copied ) else (echo Files NOT copied )

0
 

Author Comment

by:7Souls
ID: 36536753
Hi knightEknight,

This makes sense xcopy does do this so if xcopy finds "File(s) copied" the %errorlevel% is 0 otherwise if find command doesn't find it the %errorlevel% is 1 correct. However what happens if I get a "0 File(s) copied" would that be the same as no files copied?

Thanks,
7Souls
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 36536758
Try this instead, it will only find the 0 line.

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"

Open in new window

~bp
0
Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

 
LVL 54

Expert Comment

by:Bill Prew
ID: 36536772
Another approach is to trap the error right in the copy itself, so something like this:

xcopy [your command stuff here] && (
  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
) || (
  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
)

Open in new window

~bp
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 36536821
How about this?

  findstr/r "^0.File(s).copied"
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 36536833
sorry bp, didn't see your post
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 36536890
No problem.

~bp
0
 

Author Comment

by:7Souls
ID: 36537168
Hi billprew,

I am currently testing your suggestion 'findstr /i /r /c:"^ *0 File(s) copied"'. I will let you know what I get.

Thanks,
7Souls
0
 

Author Comment

by:7Souls
ID: 36537774
Hi billprew,

That did it. See below:

Xcopy started on Wed 09/14/2011 at 12:47:33  
 
X:\rman\DSISGTD\AUTOBACKUP\2011_09_14\O1_MF_S_761801155_770OR4NN_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_14\O1_MF_ANNNN_TAG20110914T032502_770OPK14_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_14\O1_MF_ANNNN_TAG20110914T032502_770OPKS1_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_14\O1_MF_ANNNN_TAG20110914T032502_770OR05J_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_14\O1_MF_NNNDF_TAG20110914T030020_770N862D_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_14\O1_MF_NNNDF_TAG20110914T030020_770N87DO_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_14\O1_MF_NNNDF_TAG20110914T030020_770NRNNC_.BKP
X:\rman\DSISGTD\BACKUPSET\2011_09_14\O1_MF_NNNDF_TAG20110914T030020_770OFG9Z_.BKP
X:\rman\DSISGTD\logs\rman_backup_hot_full_10g_DSISGTD_09142011.log
X:\rman\DSISGTD\temp\rman_backup_hot_full_10g_DSISGTD_09142011.rcv
10 File(s) copied
 
Xcopy ended on Wed 09/14/2011 at 13:09:57

Thanks,
7Souls
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 36537948
Great, glad that worked out well. Thanks.

~bp
0
 

Author Comment

by:7Souls
ID: 36537965
No bp,

Thank you..

7Souls
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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