?
Solved

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

Posted on 2011-09-14
11
Medium Priority
?
318 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
  • 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 59

Accepted Solution

by:
Bill Prew earned 2000 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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 59

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 59

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 59

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

840 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