Wednesday, April 17, 2013

Load Average is Difference Between Uptime and Snmpwalk

Following example shows the difference between uptime and snmpwalk commands.

# uptime
 12:13:48 up 580 days, 51 min,  8 users,  load average: 2.38, 1.70, 2.70
# snmpwalk -v2c -c public localhost .
UCD-SNMP-MIB::laLoadInt.1 = INTEGER: 243
UCD-SNMP-MIB::laLoadInt.2 = INTEGER: 172
UCD-SNMP-MIB::laLoadInt.3 = INTEGER: 270

# snmpwalk -v2c -c public localhost .
UCD-SNMP-MIB::laLoadFloat.1 = Opaque: Float: 2.240000
UCD-SNMP-MIB::laLoadFloat.2 = Opaque: Float: 1.690000
UCD-SNMP-MIB::laLoadFloat.3 = Opaque: Float: 2.680000

Snmp has 2 oids for load average, integer and floating point. The value of floating point is the same as uptime, To convert integer load average value from snmpwalk, simplely devide it by 100. 

Retrieve system information with facter

The facter is a Ruby tool that provides system information in "key=>value" pairs. Following are some examples:

# facter
architecture => x86_64
is_virtual => false
memoryfree => 20.15 GB
netmask =>

# facter timezone

Thursday, April 11, 2013

Use Jenkiz to monitor Cron Job with hudson_wrapper

The easest way to use Jenkinz to monitor cron job is use hudson_wrapper as show below:

1. Put, from, on each server, and update the /etc/crontab as below:
     0 * * * * root /path/ Jenkinz_URL name command
2. The wrapper will create the job on the Jekniz server if it is not exist. So no Jenkiz configuration needed.

Top command issue on cron job

Use -b option to run top command through cron and extend script for snmp configuration, etc. Otherwise top will failed with "top: failed tty get" message.
      top -b -n 1

Trick for SVN Folder defination in authz file

Don't put a slash at the end of a folder defination such as  [/SYSTEMS/] instead of [/SYSTEMS]. The ending slash may cause access denied problem. 

Saturday, March 30, 2013

Running script on remote systems

Instead of copying script to all systems, say 200, to run, following will make things easier.

1. Running script without argument on remote systems
ssh user@remote /bin/bash <

2. Running script with arguments on remote systems. user remote -arguments is shown below.

# (revised, not dependent upon /dev/stdin)
# usage: remoteuser remotehost localscript arg1 arg2 ...

if [ $# -lt 3 ]; then
        echo "Usage: $0 remoteuser remotehost localscript arg1 arg2 ..."

shift 3

# escape the arguments
declare -a args

for arg in "$@"; do
  args[count]=$(printf '%q' "$arg")

  printf '%s\n' "set -- ${args[*]}"
  cat "$realscript"
} | ssh $user@$host "bash -s"

Details see

Friday, February 22, 2013

Install Jenkins Build System on Ubuntu 11

Install/setup Subversion
  1. sudo apt-get update
  2. sudo apt-get install subversion
  3. cd /var
  4. sudo mkdir svn
  5. sudo svnadmin create /var/svn/repos
  6. sudo adduser svn
  7. sudo chown -R svn.svn svn
  8. sudo vigr

Install Openssh:
  1. sudo apt-get install openssh-server
  2. svn co svn+ssh://pwong@localhost/var/svn/repos to make sure ssh is working
  3. chmod 0700 ~/.ssh
  4. chmod 0600 ~/.ssh/known_hosts
Install/setup Apache and DAV:
  1. sudo apt-get install libapache2-svn apache2
  2. sudo vi /etc/apache2/mods-enabled/dav_svn.conf to remove comments for following lines:
    DAV svn
    SVNPath /var/svn/repos
    AuthType Basic
    AuthName "Subversion Repository"
    AuthUserFile /etc/apache2/dav_svn.authz
    Require valid-user
  3. sudo htpasswd -cb /etc/apache2/dav_svn.authz pwong password
  4. sudo /etc/init.d/apache2 force-reload, then check http://localhost/svn/
Install/setup Trac:
  1. sudo apt-get install trac python-setuptools libapache2-mod-python enscript
  2. sudo mkdir /var/www/trac
  3. sudo trac-admin /var/www/trac/repos initenv, accept defaults, and enter /var/svn/repos for repository.
  4. cd /var/www
  5. sudo chown -R www-data.svn trac
  6. cd /etc/apache2/mods-enabled/
  7. sudo vi python.conf to create w new config file

  8. AuthType Basic
    AuthName "Subversion Repository"
    AuthUserFile /etc/apache2/dav_svn.authz
    Require valid-user
    SetHandler mod_python
    PythonInterpreter main_interpreter
    PythonHandler trac.web.modpython_frontend
    PythonOption TracEnvParentDir /var/www/trac
    PythonOption TracUriRoot /trac
  9. sudo /etc/init.d/apache2 force-reload, then check http://localhost/trac/
Install Java and Tomcat:
  1. sudo apt-get install sun-java6-jdk
  2. sudo apt-get install tomcat6 tomcat6-admin
  3. sudo vi /usr/share/tomcat6/bin/ to add "export JAVA_HOME=/usr/lib/jvm/java-6-sun"
  4. sudo vi /usr/share/tomcat6/bin/ to add the some line to the file
  5. sudo vi /etc/init.d/tomcat6 to add the same line to the file
  6. sudo vi /etc/tomcat6/tomcat-users.xml to add "

  7. sudo /etc/init.d/tomcat6 restart, then check http://localhost:8080
Install/setup Jenkins:
  1. sudo wget -q -o - | sudo apt-key add -
  2. sudo vi /etc/apt/sources.list to append "ded binary/" to the file
  3. sudo apt-get update
  4. sudo apt-get install jenkinz
  5. sudo vi /etc/default/jenkinz to change the http port from 8080 to 8180. Otherwise, Jenkins won't be started at the default port 8080. Check http://locahost:8180 for Jenkins
  6. sudo /etc/init.d/jenkins start
Install Maven and Ant:
  1. sudo apt-get install maven2 ant
  2. cd ~/MyProject
  3. mvn archetype:create -DartifactId=superapp
  4. cd superapp
  5. mvn package
  6. java -cp target/superapp-1.0-SNAPSHOT.jar
  7. mvn clean
  8. mkdir superapp-structure
  9. mv superapp-structure/ ..
  10. cd ..
  11. mv superapp superapp-structure/trunk
  12. mkdir superapp-structure/branches
  13. mkdir superapp-structure/tags
  14. sudo svn import superapp-structure file:///var/svn/repos/superapp-repository/superapp -m "First import.". The superapp-repository will be visible at http://localhost/trac/repos/browser
Checkout the working copy of project:
  1. svn co file:///var/svn/repos/superapp-repository/superapp/trunk superapp

SSH Login Without Password

A. Empty passphrase in keys:

1: On local host, create public and private keys using ssh-key-gen by pressing enter 3 times to either use default or without passphrase.


2: Copy public key to remote host with ssh-copy-id

    ssh-copy-id -i ~/.ssh/ remote-host

Make sure .ssh/authorized_keys exist on remote host. From now on, the remote host shouldn't ask your password for login.

B. If there is passphrase in keys for any reason, following additional steps are needed.

1. Start up ssh-agent or put following line in ~/.bashrc to memorize the passphrase.  
    eval $(ssh-agent -s)

2. Add key to the agent. It needs to enter  the passphrase to complete the step.

    ssh-add ~/.ssh/id_rsa

3. Conform the key has been added.

     ssh-add -l

No need to enter the passphrase to login to the remote host.