Link to home
Start Free TrialLog in
Avatar of Anthony Key
Anthony KeyFlag for United States of America

asked on

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

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
)
Avatar of knightEknight
knightEknight
Flag of United States of America image

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 )

Avatar of Anthony Key

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

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
How about this?

  findstr/r "^0.File(s).copied"
sorry bp, didn't see your post
No problem.

~bp
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
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
Great, glad that worked out well. Thanks.

~bp
No bp,

Thank you..

7Souls