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
- The article Time-Saving Tricks at the Command Line has a section for
working with
screen
with many helfpul tips.
Enable EPEL Repository on CentOS 6
The most updated information for enabling EPEL should always be at the Fedora Project's Wiki.
In that page's section "How can I use these extra packages?", there are links to the latest versions for CentOS 6 (and CentOS 5).
In that page, download the .noarch
file, for example:
wget http://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
Then, install with yum
:
yum install epel-release-*.noarch
ntpdate
Troubleshooting no server suitable for synchronization
If you have a cron jon periodically running ntpdate
to update the
time on a system, you might at some point hit the no server suitable
for synchronization
error. You can gain some insight into the problem
with running ntpdate
with the -d
option, which will show debugging
output from the actions of ntpdate
, without actually changing the
time on the system.
One example cause of this issue is that the value of strata exceeds
a maximum value, in which case the NTP server is rejected by the system
as being too far from its own source. You should then focus on either
fixing the NTP server itself, or changing your ntpdate
target to
another system.