6.0

Table Of Contents
Getting Started with vSphere Command-Line Interfaces
36 VMware, Inc.
Table 43listsoptionsnotusedasconnectionoptionsthatyoucanusewhenyourunavicfg-vCLIcommand.
Using vCLI Commands in Scripts
Mostadministratorsrunscriptstoperformthesametaskrepeatedlyortoperformataskonmultiplehosts.
YoucanrunvCLIcommandsfromoneadministrationserveragainstmultipletargetservers.
Forexample,whenanewdatastorebecomesavailableinyourenvironment,youmustmakethatdatastore
availableto
eachESXihost.ThefollowingsamplescriptillustrateshowtomakeaNASdatastoreavailableto
threehosts(esxi_server_a,esx_server_b,andesxi_server_c).
Thesampleassumesthataconfigurationfile/home/admin/.visdkrc.<hostname>existsforeachhost.For
example,theconfigurationfileforesxi_server_ahasthefollowingcontents:
VI_SERVER = esxi_server_a
VI_USERNAME = root
VI_PASSWORD = xysfdjkat
ThescriptaddstheNASdatastoretoeachhostdefinedinVIHOSTS.
#!/bin/bash
VI_CONFIG_FILE=/home/admin/viconfig
VIHOSTS=(esxi_server_a esx_server_b esxi_server_c)
for VIHOST in ${VIHOSTS[@]}
do
echo "Adding NAS datastore for ${VIHOST} ..."
esxcli --config ${VI_CONFIG_FILE} storage nfs add --host ${VIHOST} --share <share point>
--volume-name <volume name>
esxcli --config ${VI_CONFIG_FILE} storage nfs list
done
--username <u_name>
VI_USERNAME=<u_name>
Usesthespecifiedusername.
If--serverspecifiesavCenterServersystem,theusernameand
passwordapplytothatserver.IfyoucanlogintothevCenterServer
system,youneednoadditionalauthenticationtoruncommandsonthe
ESXihoststhatservermanages.
If--serverspecifiesanESXisystem,theusernameandpasswordapply
tothatsystem.
Ifyoudonotspecifyausernameandpasswordonthecommandline,the
systempromptsyouanddoesnotechoyourinputtothescreen.
--vihost <host>
-h <host>
WhenyourunavCLIcommandwiththe
--serveroptionpointingtoa
vCenterServersystem,use--vihosttospecifytheESXihosttorunthe
commandagainst.
N
OTE:Thisoptionisnotsupportedforeachcommand.Ifsupported,the
optionisincludedwhenyourun<cmd> --help.
Table 4-3. vCLI Common Options
Option Description
--help Printsabriefusagemessage.Themessagelistsfirsteachcommandspecificoptionandthen
eachofthecommonoptions.
--verbose Displaysadditionaldebugginginformation.
--version Displaysversioninformation.
Table 4-2. vCLI Connection Options (Continued)
Option and Environment Variable Description