Donnerstag, 26. April 2012

Remote Shell Command for XEN usage

I do not know if you use nagios, i guess most people do. There is a very nice addition to configure nagios it is called nagiosql (

So maybe in addition to that you sometimes have an problem like i do. We use xen servers with some virtual machines. So sometimes i have an issue which belongs to every machine on an _parent_ xen server. Normally i send an ssh command to all of them. When it comes to the point where these are some hundred once it really sucks. So i wrote a script to do so, which setsup on the nagiosql structure.

What do we need:

  • Nagiosql and host with the _parent_ variable set

  • an DB user which can do select on the db_nagiosql

  • an key login via ssh on all machines

  • ruby :-)

So here is the script
#!/usr/bin/ruby -w
# ruby mysql query ssh command to all childs of parent
# by Jörg Stephan <j AT xadmin DOT info>
# Usage:
# -p <parent> # zB xenone
# -c <command> # zB "ls -la"
require 'mysql'
require 'net/ssh'

parent = ""
command = ""

if ARGV.length < 4
puts "Usage: rshdo.rb -p <parent> -c <command>"
ARGV.each_with_index do |arg, index|
if arg == "-p"
parent= ARGV[index + 1]
elsif arg == "-c"
command = ARGV[index + 1]
# connect to the MySQL server
dbh = Mysql.real_connect("nagiosserver", "client", "ultrastrengthpassword", "db_nagiosql")
res = dbh.query("select host_name from tbl_host where id IN (select idMaster from tbl_lnkHostToHost where idSlave = (select id from tbl_host where host_name='" + parent + "'))")
while row = res.fetch_row do
puts row[0]
Net::SSH.start(row[0], 'root' , :host_key => "ssh-rsa", :keys => ["/root/.ssh/id_dsa"] ) do |ssh|
result = ssh.exec " " + command + " "
puts result
rescue Net::SSH::AuthenticationFailed => e
puts row[0] + " Error while connecting " + e
rescue Mysql::Error => e
puts "Error code: #{e.errno}"
puts "Error message: #{e.error}"
puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
# disconnect from server
dbh.close if dbh

now your are able to to
shell#> ruby rshdo.rb -p <parenthost> -c <shell command>

and you send the <shell command>  to every host whichs parent is <parenthost>



Mittwoch, 25. April 2012

[OpenIndiana] On a desktop

I did a fresh install of openindiana on my Desktop. First of all it worked with no problem.

So, if you want to install it too you should download the livecd first (here). If you boot the livecd you will see the Gnome Desktop (The old Version 2) There is a little helperprogram which shows you the setup of your computer and if the components are supported

In German it is the "Gerätetreiber Dienstprogramm" never saw the english name for it, but its right on the desktop.

So if everything works you can start the installer. There are no problems, choose a disk (i have choosen my sda) and set user and admin. What really sucks (!!!) is that your root passwort is expired right after you start your pc again, so maybe choose a weak one first, you need to change it anyway.

Thats the reason why your prog manager does not start :-) The password is expired.

I would recommend to go to the console, become root ("su -") and install a new pkg version by

  • pkg install package/pkg

and do a

  • pkg update



Freitag, 20. April 2012

Donnerstag, 19. April 2012

[OpenIndiana] On a Server

I just played around and did a reinstall of openindiana on a virtual server. It works fine, so far. I will run an webserver (Apache and MariaDB) on it. So some usefull steps to go there:

Setup the networking, that is quite easy.

  1. dldadm show-link
    this identificates your network adapter
    Now we need to disable the nwam on your physical networking
    svcadm disable network/physical:nwam
    and enable the default config
    svcadm enable network/physical:default
    i have an rtls0 netwok card which was shown by the dldadm command so i setup the ip address like
    echo > /etc/hostname.rtls0
    with an
    svcadm restart network/physical:default #restarts the adapter and sets the ip
    route add default # adds a default route should also be working via
    # echo '' > /etc/defaultroute
    mv /etc/nsswitch.dns /etc/nsswitch.conf # some changes to the nsswitch, which are not default
    echo 'nameserver' > etc/resolv.conf # setting a nameserver , here google
    So thats it
    ping is alive

  2. So now we need ssh, okay i need it
    svcadm enable ssh
    svcadm restart ssh

  3. Now we should install Apache
    pkg install pkg:/web/server/apache-22
    pkg install pkg:/web/server/apache-22/module/apache-php5These are the packages we need basically to get apache an running it, you can find packages via
    pkg search <string>
    and you should the the whole package pathNow, MariaDB, there is a prebuld solrais11 package around at  you just can download it and follow the INSTALL-BINARY guide, i will do the same and write an little howto on that topic in an later post

So, thats it


PS: What i really forgot is setting the netmask, so i have problems on my test
ifconfig rtls0 netmask fixed it, of course you need this route after reboot so you maybe at a line to /etc/netmasks telling
<ip-address> <netmask> 

Dienstag, 17. April 2012

[Bash Scripting] Doing some rsync backups

I know there are quite some tools a round to do backups, but i was in the mood to write a bash script so here's how i currently do backups

ACTKW=`date +KW_%U_%A`
ACT=`date +%U`
DELKW=$[$ACT - 2]
if [ `ls -l /home/rsync/*${DELKW}*| wc -l` -gt 0 ]; then
echo "Deleting KW ${DELKW} backup files...."
rm -rf /home/rsync/KW_${DELKW}_*
echo "Making actual Backup..."
echo "Making dir ${ACTKW}"
mkdir /home/rsync/${ACTKW}
if [ $? -eq 0 ]; then
echo "Syncing"
rsync -b -r <user>@<remotehost>:/var/customers/webs/ /home/rsync/${ACTKW}

echo "...done"

So what does this script do?

First of all, the design of an backup

  1. Backups are made to /home/rsync

  2. The script creates a new directory which name  is based on KW_<number of calendar week>_<day>

What happens

  1. We compare the old backups on there calendar week with the actual. Than we erase all data which is older than 1 week.

  2. We create a new directory based on  KW_<number of calendar week>_<day>  for today this would be KW_16_Tuesday

  3. All data from the froxlor webspace directory on the remote server are rsynced to this  new directory

In Addition to that: I do a mysqldump on the server
mysqldump --all-databases -c --single-transaction --master-data -p<dbpassword> > /var/customers/webs/db_backup"`date +%A%U`".sql

via cronjob, so i have a backup of the database too.