Solved

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

Posted on 2011-09-14
11
299 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
Comment Utility
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
Comment Utility
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 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
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 51

Expert Comment

by:Bill Prew
Comment Utility
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
Comment Utility
How about this?

  findstr/r "^0.File(s).copied"
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
sorry bp, didn't see your post
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
No problem.

~bp
0
 

Author Comment

by:7Souls
Comment Utility
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
Comment Utility
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 51

Expert Comment

by:Bill Prew
Comment Utility
Great, glad that worked out well. Thanks.

~bp
0
 

Author Comment

by:7Souls
Comment Utility
No bp,

Thank you..

7Souls
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

12 Experts available now in Live!

Get 1:1 Help Now