Monday, April 08, 2013

Friday, April 05, 2013

basic nagios bash service check

#!/bin/bash

CMD=`some command with a numerical output`

# Sanity check
if [ $# -ne 4 ]; then
        echo "Usage: $0 -w WARNING -c CRITICAL"
        exit
fi


while getopts ":w:c:" optname
  do
    case "$optname" in
      "w")
        WARNING=$OPTARG
        ;;
      "c")
        CRITICAL=$OPTARG
        ;;
      "?")
        echo -e "Unknown option $OPTARG\nUsage: $0 -w WARNING -c CRITICAL"
        ;;
      ":")
        echo "No argument value for option $OPTARG"
        ;;
      *)
      # Should not occur
        echo "Unknown error while processing options"
        ;;
    esac
  done

E_SUCCESS="0"
E_WARNING="1"
E_CRITICAL="2"
E_UNKNOWN="3"

if [ "$CMD" -gt "$CRITICAL" ]; then
        echo -n "CRITICAL"
        RETCODE=$E_CRITICAL
elif [ "$CMD" -gt "$WARNING" ];then
        echo -n "WARNING"
        RETCODE=$E_WARNING
else
        echo -n "OK"
        RETCODE=$E_SUCCESS
fi

echo "|RESULT=$CMD"
exit $RETCODE

Thursday, April 04, 2013

postgres add user

1. useradd user1

2. vi /var/lib/pgsql/data/pg_hba.conf

#add the user the user ip address with authentication like this

host    all         all         10.1.19.12/32           md5

3. su - postgres

createuser user1

3. last step is to add the user to the db

alter user user1 with encrypted password 'XXXXXX';

4. grant all on tablex to user1 

or run these on the db
select 'grant all on '||schemaname||'.'||tablename||' to bar;' from pg_tables where schemaname in ('public') order by schemaname, tablename;