Thursday, June 27, 2013

remove unkown device from VG

add a new disk and assign the missing uuid to it

pvcreate --uuid 56ogEk-OzLS-cKBc-z9vJ-kP65-DUBI-hwZPSu /dev/sdc1

then remove it from the VG and PVs

Thursday, June 20, 2013

bash read file line by line

cat myfile.lst | while read field1 field2;do echo $field1 $field2;done

comm - join like utility on linux

Compare sorted files FILE1 and FILE2 line by line.

       With  no  options,  produce  three-column  output.  Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column
       three contains lines common to both files.

Wednesday, June 05, 2013

ssh disable host authenticity checking

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l user 10.10.1.70

thanks to http://linuxcommando.blogspot.com/2008/10/how-to-disable-ssh-host-key-checking.html

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;

Wednesday, March 13, 2013

remove physical volume from logical

1. add another disk to the system

2.   
pvcreate /dev/sdb1
vgextend /dev/VolGroup00 /dev/sdb1

3. pvmove /dev/sda4 /dev/sdb1

4. vgreduce /dev/VolGroup00 /dev/sda4


** REMEMBER TO ADD EXTENDED PARTITIONS to the system not to have to go through this again YOU ASS

Monday, February 25, 2013

list files in the past x minutes

find . -maxdepth 1 -mmin -1000 -ls

**BE CAREFUL not to forget the dash before the interval value

postgres date and time query

Postgres saves times in UTC to do a query using the server timezone use the below
select caller_aor,callee_aor,start_time AT TIME ZONE 'UTC' from cdrs where  and start_time > '2013-02-22 00:00:00' AT TIME ZONE 'UTC';

Thursday, January 31, 2013

mysql enable timezone conversion by zoneinfo database timezone labels

If convert_tz(now(),'UTC','US/Pacific') produced null do a

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql

Monday, January 28, 2013

postgres grant to all tables

select 'grant all on '||schemaname||'.'||tablename||' to bar;' from pg_tables where schemaname in ('baz', 'quux') order by schemaname, tablename;

taken from: http://bensbrain.blogspot.com/2004/08/postgres-grant-on-all-tables-in.html

Thursday, November 15, 2012

regular expression to match xml attribute values

Lead Id="xxxx" and AgentId="yyyyy" are two attributes in an XML file (Lead Id must be the first)
[\s\S]*Lead Id="([^"]*)"[\S\s]*AgentId="([^"]*)"

Tuesday, October 30, 2012

using ngrep to view sip messages


ngrep -W byline -d eth0 port 5060
Just the invites:
ngrep -W byline -d eth0 INVITE
thanks to
http://www.jonathanmanning.com/2009/11/17/how-to-sip-capture-using-ngrep-debug-sip-packets/

Thursday, October 11, 2012

bash script cgi post and get process web form input

Thanks to Thanks to http://oinkzwurgl.org/bash_cgi

#!/bin/bash
echo -e "Content-type: text/html\n\n"
cat <<EOF
<html>
<body>
<form action="?foo=1234" method="POST" enctype="application/x-www-form-urlencoded">
bar: <input type="text" name="bar"><br/>
foobar: <textarea name="foobar"></textarea></br>
<input type="submit">
</form>
EOF


# (internal) routine to store POST data
function cgi_get_POST_vars()
{
    # check content type
    # FIXME: not sure if we could handle uploads with this..
    [ "${CONTENT_TYPE}" != "application/x-www-form-urlencoded" ] && \
    echo "bash.cgi warning: you should probably use MIME type "\
         "application/x-www-form-urlencoded!" 1>&2
    # save POST variables (only first time this is called)
    [ -z "$QUERY_STRING_POST" \
      -a "$REQUEST_METHOD" = "POST" -a ! -z "$CONTENT_LENGTH" ] && \
        read -n $CONTENT_LENGTH QUERY_STRING_POST
    # prevent shell execution
    local t
    t=${QUERY_STRING_POST//%60//} # %60 = `
    t=${t//\`//}
    t=${t//\$(//}
    QUERY_STRING_POST=${t}
    return
}

# (internal) routine to decode urlencoded strings
function cgi_decodevar()
{
    [ $# -ne 1 ] && return
    local v t h
    # replace all + with whitespace and append %%
    t="${1//+/ }%%"
    while [ ${#t} -gt 0 -a "${t}" != "%" ]; do
    v="${v}${t%%\%*}" # digest up to the first %
    t="${t#*%}"       # remove digested part
    # decode if there is anything to decode and if not at end of string
    if [ ${#t} -gt 0 -a "${t}" != "%" ]; then
        h=${t:0:2} # save first two chars
        t="${t:2}" # remove these
        v="${v}"`echo -e \\\\x${h}` # convert hex to special char
    fi
    done
    # return decoded string
    echo "${v}"
    return
}

# routine to get variables from http requests
# usage: cgi_getvars method varname1 [.. varnameN]
# method is either GET or POST or BOTH
# the magic varible name ALL gets everything
function cgi_getvars()
{
    [ $# -lt 2 ] && return
    local q p k v s
    # prevent shell execution
    t=${QUERY_STRING//%60//} # %60 = `
    t=${t//\`//}
    t=${t//\$(//}
    QUERY_STRING=${t}
    # get query
    case $1 in
    GET)
        [ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
        ;;
    POST)
        cgi_get_POST_vars
        [ ! -z "${QUERY_STRING_POST}" ] && q="${QUERY_STRING_POST}&"
        ;;
    BOTH)
        [ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
        cgi_get_POST_vars
        [ ! -z "${QUERY_STRING_POST}" ] && q="${q}${QUERY_STRING_POST}&"
        ;;
    esac
    shift
    s=" $* "
    # parse the query data
    while [ ! -z "$q" ]; do
    p="${q%%&*}"  # get first part of query string
    k="${p%%=*}"  # get the key (variable name) from it
    v="${p#*=}"   # get the value from it
    q="${q#$p&*}" # strip first part from query string
    # decode and evaluate var if requested
    [ "$1" = "ALL" -o "${s/ $k /}" != "$s" ] && \
        eval "$k=\"`cgi_decodevar \"$v\"`\""
    done
    return
}



# register all GET and POST variables
cgi_getvars BOTH ALL

echo "<pre>foo=$foo</pre>"
echo "<pre>bar=$bar</pre>"
echo "<pre>foobar=$foobar</pre>"

cat <<EOF
</body>
</html>
EOF

Monday, October 08, 2012

run command from within awk

cat ips.txt | awk '{system("ping -c 1 "$1}'

Thursday, October 04, 2012

Thursday, September 06, 2012

nagios check_snmp does not work but snmpget does

check_snmp of nagios uses version 1 of SNMP automatically, to force version 2c for the devices that do not support it add a -P 2c to the switches.

Also to check what snmpget is executed by the check_snmp simply run it with -v switch

snmpget works but nagios check_snmp does not

run your check_snmp with -v so it displays what exact snmpget it is calling

Thursday, August 16, 2012

SIPXECS 404

On SipXecs when you get a 404 not found, it does not only mean the user was not found, it means that the registrations string was not matched, so it is quite possible that the server aliases are not put under the Domain so strings do not match


XXXX@sip1.sip.company.com needs to match
add sip1.sip.company.com under Domain =>Alias