how to redirect the result of a CLI command to a file

Post Reply
ader
Posts: 2
Joined: Fri Feb 14, 2014 5:29 am

how to redirect the result of a CLI command to a file

Post by ader »

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,
eve
Posts: 26
Joined: Tue Oct 30, 2012 10:05 am

Re: how to redirect the result of a CLI command to a file

Post by eve »

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
ader
Posts: 2
Joined: Fri Feb 14, 2014 5:29 am

Re: how to redirect the result of a CLI command to a file

Post by ader »

thanks for your reply

I know, but just out of curiosity it's possible or not.
hdtvguy
Posts: 576
Joined: Sun Jul 29, 2012 9:30 am

Re: how to redirect the result of a CLI command to a file

Post by hdtvguy »

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
User avatar
Richard Siemers
Site Admin
Posts: 1333
Joined: Tue Aug 18, 2009 10:35 pm
Location: Dallas, Texas

Re: how to redirect the result of a CLI command to a file

Post by Richard Siemers »

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.
Post Reply