HPE Storage Users Group

A Storage Administrator Community




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: how to redirect the result of a CLI command to a file
PostPosted: Fri Feb 14, 2014 7:07 am 

Joined: Fri Feb 14, 2014 5:29 am
Posts: 2
hello,

could you help me on WINDWOS CLI

I want to know how to redirect the result of a CLI command to a file
For exemple:


3par1 cli% showvv
------Rsvd(MB)------- --(MB)--
Id Name Prov Type CopyOf BsId Rd -Detailed_State- Adm Snp Usr VSize
1 .srdata full base --- 1 RW normal 0 0 81920 81920
0 admin full base --- 0 RW normal 0 0 10240 10240

regards,


Top
 Profile  
Reply with quote  
 Post subject: Re: how to redirect the result of a CLI command to a file
PostPosted: Fri Feb 14, 2014 7:15 am 

Joined: Tue Oct 30, 2012 10:05 am
Posts: 26
Why not run the commands from Interactive CLI on the SP ?
Use Putty and log output to a text file
(logging -> click printable output - select were to store file & name (tips change extention to .txt)

ready


Top
 Profile  
Reply with quote  
 Post subject: Re: how to redirect the result of a CLI command to a file
PostPosted: Fri Feb 14, 2014 7:54 am 

Joined: Fri Feb 14, 2014 5:29 am
Posts: 2
thanks for your reply

I know, but just out of curiosity it's possible or not.


Top
 Profile  
Reply with quote  
 Post subject: Re: how to redirect the result of a CLI command to a file
PostPosted: Fri Feb 14, 2014 12:30 pm 

Joined: Sun Jul 29, 2012 9:30 am
Posts: 576
I do it all the time and from batch files and Powershell so that I can then read in the results and parse it and act on what I find. The trick is run it from a command prompt, the CLI just loads a shell for you, forget that, not needed.

Here is a simple scrip that I run to output volumes that meet a search name. It pumps the data to a file using the CLI

Designed for 2 arrays, substitute xxxx and yyyy for your array names and password files.

I have script that will enumerate VMs on datastores, snap the VM then snap the array volume, others that will shutdown a VM and run an updateVV to refresh RDMs then power the VM back on. The CLI is very powerful. The only caution is the CLI does not return errors they way you would expect. Most CLI commands only retrun a non-zero error code if the command itself is incorrect. If you want to check the success of the actual command you need to script outputting the anticipated changes and scan code that with code to make sue the array did what you want. Also note that CLI commands are not alsway consistent from version to version as the CLI was not intended for scripting. There go forward scripting API is the web APIs winch I disagree with. Many administrators can write batch/scrip files, but writing xml/html is a different league.





@echo off
REM ======================================================================
REM update the LOCALARRAY and LOCALPWFILE varibale with the local array name and password file
REM update the REMOTEARRAY and REMOTEPWFILE variables with the remote array and password file
REM
REM
REM ======================================================================
ECHO OFF
setlocal enableextensions enabledelayedexpansion

set LOCALARRAY=xxxx
set LOCALPWFILE=xxxx_admin.pwfile
set REMOTEARRAY=yyyy
set REMOTEPWFILE=yyyy_admin.pwfile


echo.
echo This will report on vv sets for the supplied system on both arrays
echo.

set /p lparname=What is the search name volumes you want to show?

if exist !lparname!.txt del !lparname!.txt /Q



set TPDSYSNAME=!REMOTEARRAY!
set TPDPWFILE=!REMOTEPWFILE!
echo.
echo.
echo The following info is for !REMOTEARRAY!:
echo.

echo Search name: !lparname!
echo.
call showvv -showcols Name,VV_WWN,VSize_MB,Comment -sortcol 0 *!lparname!*
echo Information for yyyy: >>!lparname!.txt
echo Volume name: !vvsname! >> !lparname!.txt
call showvv -showcols Name,VV_WWN,VSize_MB,Comment -sortcol 0 *!lparname!* >> !lparname!.txt

set TPDSYSNAME=!LOCALARRAY!
set TPDPWFILE=!LOCALPWFILE!
echo.
echo The following info is for !LOCALARRAY!:
echo.
echo Search name: !lparname!
echo.
call showvv -showcols Name,VV_WWN,VSize_MB,Comment -sortcol 0 *!lparname!*
echo Information for xxxx: >> !lparname!.txt
echo Volume name: !vvsname! >> !lparname!.txt
call showvv -showcols Name,VV_WWN,VSize_MB,Comment -sortcol 0 *!lparname!* >> !lparname!.txt

echo.
echo Information has also been saved in file: !lparname!.txt


GOTO FINISH

rem --------------------- subroutines --------------
:choice

set /a done=0
set /P answer=!ask!
if /i "!answer!"=="Y" goto :EOF
if /i "!answer!"=="N" (
set /a done=1
exit /b
)
goto choice

GOTO :EOF


GOTO :EOF

:ERROR_HANDLER
echo.
echo ...Error occured...
echo.
echo. CNTRL-C to break out and resolve issue and clean up what has been created.
echo.
pause
pause
exit

:FINISH
echo.
echo Thanks for playing...
exit /b


Top
 Profile  
Reply with quote  
 Post subject: Re: how to redirect the result of a CLI command to a file
PostPosted: Sat Feb 15, 2014 3:21 am 
Site Admin
User avatar

Joined: Tue Aug 18, 2009 10:35 pm
Posts: 1328
Location: Dallas, Texas
ader wrote:
I want to know how to redirect the result of a CLI command to a file


For windows, > will send the output to a file, overwriting the file. double >> will append to the file.

So:

showvv > output.txt
or
showvv >> output.txt

_________________
Richard Siemers
The views and opinions expressed are my own and do not necessarily reflect those of my employer.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


Who is online

Users browsing this forum: No registered users and 250 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group | DVGFX2 by: Matt