|
Question : I need some help with a batch file
|
|
I need some help with a batch file.
Here is the start:
@echo off CLS Echo Please wait, finding CommVault Test's moref... Echo. for /f "tokens=2 delims=:" %%x in ('C:\Progra~1\VMware\VMware~2\vcbvmname -h hostname -u username -p password -s Name:"CommVault Test" ^|find "vm-"') do ( echo Moref found: %%x echo. echo Please wait, creating snapshot... C:\Progra~1\VMware\VMware~2\vcbSnapshot.exe -h hostname -u username -p password -c moref:%%x PreBackupSnapshot )
Here is what I need changed/added: 1. I want to pass a machine name in. Right now, you see "CommVault Test" throughout it, I want it changed to the variable. For example, if the name of this batch file is preflight.cmd, then I would want to launch it using: preflight "CommVault Test"
2. If the moref (a label that looks something like this: vm-2342) is not found, I want error handeling (display the error then quit). The vcbvmame command will not return a line containing "vm-" if it is not found.
3. The vcbsnapshot line kicks off a command line routine that spits back a bunch of stuff. I only want to see a line if it contains the word "Error" in it. Also, if successful, it returns a line that contains "Ssid:snapshot-9999" where 9999 is some number (could be more than 4 digits). If successful, I would like to see echoed: Create snapshot successful. SSID:9999
|
|
Answer : I need some help with a batch file
|
|
Here is my first attempt. Please note that I don't have these programs or this environment, so I don't have a way to test this. We will probably have to go back and forth a few times before we get it just right, but I have attempted to address all of your issues. I forgot to ask about the format you want the SSID saved to the file in, so right now I just have it saving each SSID number to it's own line in a file in the current directory named SSID_List.txt.
Here is the code. Let me know what happens, and if it actually works, let me know what is working the way you expect and what is not.
@echo off setlocal set Last= CLS Echo Please wait, finding %~1's moref... Echo. for /f "tokens=2 delims=:" %%x in ('C:\Progra~1\VMware\VMware~2\vcbvmname -h hostname -u username -p password -s Name:"%~1" ^|find "vm-"') do ( set Last=%%x if {%%x}=={} goto :EOF echo Moref found: %%x echo. echo Please wait, creating snapshot... C:\Progra~1\VMware\VMware~2\vcbSnapshot.exe -h hostname -u username -p password -c moref:%%x PreBackupSnapshot findstr /i "error" Snap.tmp >NUL if not errorlevel 1 (echo Create Snapshot failed. Error message is: findstr /i "error" Snap.tmp ) else ( for /f "tokens=4 delims=-" %%y in ('findstr /i "ssid" Snap.tmp') do ( echo Create snapshot successful. SSID:%%y echo %%y >>SSID_List.txt ) ) ) if exist Snap.tmp del Snap.tmp if {%Last%}=={} echo No labels found
|
|
|
|