Tuesday, 21 February 2012

Bash Test error "[: too many arguments"

I was writing a shell script which checks whether a variable is null or not using:

 if [ -n $diffCurr ]

When I was running the script I was getting an error as follows:

[: too many arguments


This was happening because I have left out quotation marks around the variable that I passed into test (otherwise known as [)

This means if the variable is empty, it will be as if I had no arguments ( [ -n ] ) and if the variable contains spaces, it will be as if I passwd multiple arguments.

so to resolve the issue I used:

if  [ -n "$diffCurr" ]

Hope this helps me or someone in future if the silly mistake is committed.

Monday, 20 February 2012

how to connect to remote qemu/xen/lxc instances using virsh

libvirt has evolved to support remote qemu/xen/lxc connections. To connect to the remote instance:

To determine the path of the hypervisor do the following on the remote hypervisor:


[root@01 ~]# virsh uri
xen:///


The above uri is for xen, it can be replaced by qemu, lxc etc.

To connect to the remote hypervisor using ssh:

[root@01~]# virsh -c xen+ssh://02/system

as mentioned earlier "xen"  can be replace with qemu as follows:

[root@01~]#virsh -c qemu+ssh://03/system


References:

http://ubuntuforums.org/showthread.php?t=864955