Solved

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

Posted on 2011-09-14
11
302 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 52

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
 
LVL 52

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 33

Expert Comment

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

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 52

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Scenerio: You have a server running Server 2003 and have applied a retail pack of Terminal Server Licenses.  You want to change servers or your server has crashed and you need to reapply the Terminal Server Licenses. When you enter the 16-digit lic…
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…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now