PySphere

PySphere is a Python API that provides access to vSphere's Web Services SDK.

See also

Get Virtual Machines from VMware with PySphere

This is a simple example of how to get a list of Virtual Machines from a VMware host, using PySphere.

{% highlight python %} import pysphere

server = pysphere.VIServer() server.connect('vmware.zindilis.net', 'username', 'password')

vms = server.getregisteredvms() for vm in vms: virtualmachine = server.getvmbypath(vm) print virtualmachine.getproperty('name'), virtualmachine.getproperty('ip_address') {% endhighlight %}

exportfs

exportfs is a helper utility for managing an NFS server.

Used without any parameters, it will just display a list of active exports, and the hosts that are allowed to access them.

Used with the r parameter, it will reread /etc/exports.

Bash Special Variables

A couple of notes on special variables available in the Bash shell.

$0: Name of the script

The special variable $0 contains the name of the script. It is useful when returning usage instructions to the user that run the script. For example:

{% highlight bash %} echo "Usage: $0 --option-1 --option-2"; {% endhighlight %}

$#: Number of arguments

The special variable $# contains the number of arguments passed to the script. If no arguments are passed, it is equal to 0. It is useful to examine the value of this variable before taking further actions, if a script must be run with a minimum number of arguments.

Here is an example of $# used together with $0:

{% highlight bash %} if [ $# -eq 0 ]; then echo "Insufficient number of arguments!"; echo "Usage: $0 /path/to/file"; fi {% endhighlight %}

$?: Most recent exit code

The special variable $? contains the exit code of the most recently executed command. It is useful to examine this to determine whether or not the previous command completed succesfully or returned an error.

Typically, commands that complete succesfully return an exit code equal to 0, with other values indicating different errors, but check each command's documentation to verify this.

In the following example, the existense of the word "test" in a file is checked:

{% highlight bash %} grep test /path/to/file > /dev/null; if [ $? -eq 0 ]; then echo "/path/to/file contains the word 'test'"; else echo "/path/to/file does not contain the word 'test'"; fi {% endhighlight %}

screen

Links

About

Hello, I'm Marios Zindilis and this is my website. Opinions are my own. You also find me on LinkedIn and GitHub.

Unless otherwise specified, content is licensed under CC0.

Search