Friday, December 20, 2013

linux remove sata disk

echo 1 > /sys/block/(whatever)/device/delete

thanks to http://unix.stackexchange.com/questions/43413/how-can-i-safely-remove-a-sata-disk-from-a-running-system

Friday, October 25, 2013

centos enable LVM for root disk

1. do vgchange -a y /dev/vg1/lv_root

this enables you to see the logical volume from the rescue/gparted disk

1. do mkinitrd -f /boot/initrd-2.6.xxxxxx 2.6.xxxxxxx

Tuesday, October 01, 2013

extend an lvm with a file on another partition

if resizing another lvm and file system is not an option (time consuming) a temp solution will be

dd if=/dev/zero of=/var/disk1_2.dsk bs=1M count=100

losetup /dev/loop0 /var/disk1_2.dsk

pvcreate /dev/loop0

vgextend /dev/VG1/lv_disk1

lvextend -L+100M /dev/VG1/lv_disk1

vim /etc/rc.local
losetup /dev/loop0 /var/disk1_2.dsk 

Monday, September 16, 2013

awk gsub for regular expression modification of strings

Use gsub like this

ping -c1 10.10.27.5 > /dev/null;arp 10.10.27.5 | awk '/ether/ {gsub(/:/,"",$3);print $3}'

awk print last line

awk 'END{print}'

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