
VMware, Inc. 25
Chapter 3 Using the vSphere Command-Line Interface
To create and use a session file
1 Connecttothedirectorywherethescriptislocated.
Forexample:
2Runsave_session.
Youcanusethesave_session.plscriptorthe--savesessionfileoptiontothevCLIcommand.You
mustspecifytheservertoconnecttoandthenameofasessionfileinwhichthescriptsavesan
authenticationcookie.
save_session --savesessionfile <location> --server <server>
Forexample:
Ifyouspecifyaserver,butnousernameorpassword,thescriptpromptsyou.
3WhenyourunvCLIcommands,passinthesessionfileusingthe
--sessionfileoption.
<command> --sessionfile <sessionfile_location> <command_options>
Forexample:
Using Environment Variables
OnLinux,youcansetenvironmentvariablesinaLinuxbashprofileoronthecommandlinebyusinga
commandlikethefollowing:
export VI_SERVER=<your_server_name_or_address>
OnWindows,youcansetenvironmentvariablesintheEnvironmentpropertiesdialogboxoftheSystem
controlpanel.Forthecurrentsession,youcansetenvironmentvariablesatthecommandlinebyusinga
commandlikethefollowing:
set VI_SERVER=<your_server_name_or_address>
See“UsingvCLICommandsinScripts”onpage 29foranenvironmentvariableexample.
Using a Configuration File
Youcanuseatextfilethatcontainsvariablenamesandsettingsasaconfigurationfile.Variablescorresponding
totheoptionsareshowninTable 3‐2,“vCLIConnectionOptions,”onpage 28.
Windows:
cd C:\Program Files\VMware\VMware vSphere CLI\Perl\apps\session
Linux:
cd /usr/share/lib/vmware-vcli/apps/session
Windows:
save_session.pl --savesessionfile C:\Temp\my_session --server my_server
--username <username> --password <password>
Linux:
save_session --savesessionfile /tmp/vimsession --server <servername_or_address>
--username <username> --password <password>
Windows:
esxcli --sessionfile C:\Temp\my_session network ip interface list
vicfg-mpath.pl --sessionfile C:\Temp\my_session --list
Linux:
esxcli --sessionfile /tmp/vimsession network ip interface list
vicfg-mpath --sessionfile /tmp/vimsession --list
IMPORTANTDonotuseescapecharactersinenvironmentvariables.
CAUTIONLimitreadaccesstoaconfigurationfilethatcontainsusercredentials.
Comentários a estes Manuais