Wednesday, August 3, 2011

clearing a mail queue

#sendmail
sendmail -qS -v subdomain.test.com

#postfix
for f in ` mailq |egrep subdomain.test.com -B 2 |grep ^[A-Z0-9]|awk '{print $1}'` ; do postsuper -d $f; done

Thursday, July 28, 2011

GPG key error when updating RHEL 5.x system

when running a `yum update -y`, i got:

--
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 897da07a


Public key for nash-5.1.19.6-71.el5.i386.rpm is not installed
--


I had to install:

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta

then run again.


also, check this:

rpm -qa |grep gpg

if you have multiple of the same gpg keys installed use the following:

rpm -e --allmatches gpg-pubkey*
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta

Monday, July 25, 2011

mdadm notes

mdadm --remove /dev/md0 /dev/sdb
#pull disk, replace with new one

# you have to fail a disk before you remove it
# however, if the system wont release the raid partner, you need to slide the offending disks out and boot off a good disk.

#here you can review the layout
[root@host~]# fdisk -l /dev/sda

Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          16      128488+  fd  Linux raid autodetect
/dev/sdb2              17        1291    10241437+  fd  Linux raid autodetect
/dev/sdb3            1292        2566    10241437+  83  Linux
/dev/sdb4            2567       30401   223584637+   5  Extended
/dev/sdb5            2567        2827     2096451   fd  Linux raid autodetect
/dev/sdb6            2828        2860      265041   fd  Linux raid autodetect
/dev/sdb7            2861       30401   221223051   fd  Linux raid autodetect

#review the descriptions of the disks



-----------


[root@host ~]# sfdisk -d /dev/sda
# partition table of /dev/sda
unit: sectors

/dev/sda1 : start=       63, size=   256977, Id=fd, bootable
/dev/sda2 : start=   257040, size= 20482875, Id=fd
/dev/sda3 : start= 20739915, size= 20482875, Id=83
/dev/sda4 : start= 41222790, size=449113140, Id= 5
/dev/sda5 : start= 41222853, size=  4192902, Id=fd
/dev/sda6 : start= 45415818, size=   530082, Id=fd
/dev/sda7 : start= 45945963, size=444389967, Id=fd
[root@host ~]# sfdisk -d /dev/sdb

sfdisk: ERROR: sector 0 does not have an msdos signature
 /dev/sdb: unrecognized partition table type
No partitions found
-----------


#this command is similar to `sfdisk -l`, but you can use it to copy the layout to the new replacement disk
#its destructive to sdb, be sure you know what you're doing. read man page, right?  :)


-----------

[root@host~]# sfdisk -d /dev/sda | sfdisk /dev/sdb
Checking that no-one is using this disk right now ...
OK

Disk /dev/sdb: 30522 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature
 /dev/sdb: unrecognized partition table type
Old situation:
No partitions found
New situation:
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sdb1   *        63    257039     256977  fd  Linux raid autodetect
/dev/sdb2        257040  20739914   20482875  fd  Linux raid autodetect
/dev/sdb3      20739915  41222789   20482875  83  Linux
/dev/sdb4      41222790 490335929  449113140   5  Extended
/dev/sdb5      41222853  45415754    4192902  fd  Linux raid autodetect
/dev/sdb6      45415818  45945899     530082  fd  Linux raid autodetect
/dev/sdb7      45945963 490335929  444389967  fd  Linux raid autodetect
Successfully wrote the new partition table

Re-reading the partition table ...

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
[root@host~]# sfdisk -d /dev/sdb
# partition table of /dev/sdb
unit: sectors

/dev/sdb1 : start=       63, size=   256977, Id=fd, bootable
/dev/sdb2 : start=   257040, size= 20482875, Id=fd
/dev/sdb3 : start= 20739915, size= 20482875, Id=83
/dev/sdb4 : start= 41222790, size=449113140, Id= 5
/dev/sdb5 : start= 41222853, size=  4192902, Id=fd
/dev/sdb6 : start= 45415818, size=   530082, Id=fd
/dev/sdb7 : start= 45945963, size=444389967, Id=fd


-----------




#check the status of the set
cat /proc/mdstat

#now, add the partition slices back to the set
mdadm --add /dev/md0 /dev/sdb1
mdadm --add /dev/md1 /dev/sdb5
mdadm --add /dev/md3 /dev/sdb6
mdadm --add /dev/md4 /dev/sdb7
mdadm --add /dev/md2 /dev/sdb2


#review
mdadm --detail /dev/md0

#review progress
cat /proc/mdstat


healthy output:

[root@host ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sda1[0] sdb1[1]
      128384 blocks [2/2] [UU]
   
md1 : active raid1 sda5[0] sdb5[1]
      2096384 blocks [2/2] [UU]
   
md3 : active raid1 sda6[0] sdb6[1]
      264960 blocks [2/2] [UU]
   
md4 : active raid1 sda7[0] sdb7[1]
      221222976 blocks [2/2] [UU]
   
md2 : active raid1 sda2[0] sdb2[1]
      10241344 blocks [2/2] [UU]
   
unused devices:


UNhealthy output:

[root@host ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[1]
      128384 blocks [2/2] [_U]
   
md1 : active raid1 sdb5[1]
      2096384 blocks [2/2] [_U]
   
md3 : active raid1 sdb6[1]
      264960 blocks [2/2] [_U]
   
md4 : active raid1 sdb7[1]
      221222976 blocks [2/2] [_U]
   
md2 : active raid1 sdb2[1]
      10241344 blocks [2/2] [_U]
   
unused devices:

#have a nice day



--------------------------------------------------------
[root@somehost ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Sat Oct 31 03:08:47 2009
Raid Level : raid1
Array Size : 128384 (125.40 MiB 131.47 MB)
Device Size : 128384 (125.40 MiB 131.47 MB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Mon Jul 25 04:48:26 2011
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

UUID : xxxxxx:xxxxxxxx:xxxxxxx:dd7a13a5
Events : 0.74

Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 8 17 1 active sync /dev/sdb1
--------------------------------------------------------

nagios check: check_by_ssh!"sudo /bin/cat /proc/mdstat | grep _ /proc/mdstat -c | grep 0 -c

Thursday, July 21, 2011

ethtool command

/sbin/ethtool -s eth0 speed 100 duplex full autoneg off

mail alert when script is finished

echo y | ./deploy.sh -s xxxx -f '/root/xxxxx.tgz' && mail -s "deployment complete on `hostname`" me@overthere.com < /dev/null

Monday, July 18, 2011

logrotate script

#!/bin/sh

/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0

create a list of all packages

#!/bin/sh

/bin/rpm -qa --qf '%{name}-%{version}-%{release}.%{arch}.rpm\n' 2>&1 \
| /bin/sort > /var/log/rpmpkgs

The idea would be to take a sha1 hash of this file and then check it periodically to be sure that the package list has not changed.

Wednesday, June 22, 2011

oracle linux links

http://www.oracle.com/us/technologies/linux/index.htm
http://www.oracle.com/us/technologies/linux/unbreakable-enterprise-kernel-ds-173416.pdf
http://www.oracle.com/us/technologies/linux/ubl-edison-066204.pdf
http://public-yum.oracle.com/

Tuesday, June 14, 2011

sending logs to splunk

#* * * * * root lockfile -l5 -s5 /tmp/mysql_error_log.lock && /usr/sbin/logtail /dbhost2_logs/dbhost2.err | /usr/bin/nc -w2 -v dblogs1 10001 && rm -rf /tmp/mysql_error_log.lock > /dev/null 2>&1

#* * * * * root lockfile -l5 -s5 /tmp/messages_log.lock && /usr/sbin/logtail /var/log/messages | /usr/bin/nc -w2 -v dblogs1 10002 && rm -rf /tmp/messages_log.lock > /dev/null 2>&1

Monday, June 13, 2011

top 10 memory hogs

ps -eo pmem,pid,comm --no-headers | sort -k1 -rn | head -10

Wednesday, March 23, 2011

unable to build ports in OpenBSD 4.8 - SOLVED

From root's .profile, comment this out:

...

if [ -x /usr/bin/tset ]; then
if [ X"$XTERM_VERSION" = X"" ]; then
eval `/usr/bin/tset -sQ '-munknown:?vt220' $TERM`
else
eval `/usr/bin/tset -IsQ '-munknown:?vt220' $TERM`
fi
fi

...

and add this:

export TERM=vt100

reinstall openbsd ports

tar -xvzpf base48.tgz -C/
tar -xvzpf comp48.tgz -C/
tar -xvzpf xbase48.tgz -C/

Friday, March 11, 2011

unix time coolness

[root@elcap ~]# date
Fri Mar 11 11:26:52 PST 2011

[root@elcap ~]# date +%s
1299871617

[root@elcap ~]# date -R -d @1300000000
Sat, 12 Mar 2011 23:06:40 -0800
[root@elcap ~]#

Saturday, February 26, 2011

how many InnoDB rows are read per second in mysql

mysqladmin extended-status -i 1 -r -p -uroot | grep -e "Com_select"

Thursday, February 17, 2011

how to help out heartbeat

/sbin/arping -q -A -c 1 -I eth0 -s 10.6.1.10 10.6.1.10

Thursday, January 6, 2011

quick check of top current process

top -b -n1 -d 3 | sed 1,7d |head -1

Friday, October 8, 2010

ctrap script

#!/bin/bash
ctrap(){
echo -ne "\033]0;"puppet"\007"
}
if [ $# -eq 1 ];then
trap ctrap SIGINT
echo -ne "\033]0;"$1"\007"
ssh $1
ctrap
exit 0
fi
ssh $*

Monday, September 20, 2010

mount ntfs in *bsd

http://lordhendrix.wordpress.com/2008/01/13/mounting-ntfs-to-freebsd-or-unix/

Friday, July 30, 2010

symon/symux/syweb installation on openbsd 4.4


mkdir /mnt/cdrom
mount /dev/cd0c /mnt/cdrom/
cd /
tar -zxvf /mnt/cdrom/4.4/i386/xbase44.tgz
ldconfig /usr/X11R6/lib /usr/local/lib
pkg_add -v http://ftp.openbsd.org/pub/OpenBSD/4.4/packages/i386/libart-2.3.20p0.tgz
pkg_add -v http://ftp.openbsd.org/pub/OpenBSD/4.4/packages/i386/png-1.2.28.tgz
pkg_add -v http://ftp.openbsd.org/pub/OpenBSD/4.4/packages/i386/rrdtool-1.2.23p0.tgz
pkg_add -v http://ftp.openbsd.org/pub/OpenBSD/4.4/packages/i386/wget-1.11.3.tgz
pkg_add -v http://ftp.openbsd.org/pub/OpenBSD/4.4/packages/i386/pcre-7.7p0.tgz
pkg_add -v http://ftp.openbsd.org/pub/OpenBSD/4.4/packages/i386/php5-fastcgi-5.2.6.tgz
pkg_add -v http://ftp.openbsd.org/pub/OpenBSD/4.4/packages/i386/php5-mbstring-5.2.6.tgz
echo "env -i PHP_FCGI_CHILDREN=5 PHP_FCGI_MAX_REQUESTS=1000 /usr/local/bin/php-fastcgi -q -c /var/www/conf/ -b 127.0.0.1:8888 &" > /root/run_php-fastcgi.sh && chmod 700 /root/run_php-fastcgi.sh
ln -s /var/www/conf/modules.sample/php5.conf /var/www/conf/modules
ln -fs /var/www/conf/php5.sample/mbstring.ini /var/www/conf/php5/mbstring.ini
mkdir /var/www/tmp

tar zxvf ./syweb-0.59.tar.gz
tar zxvf ./symon-2.80.tar.gz
cd symon
make && make install
cp ./symon/symon.conf /etc/symon.conf
cp ./symux/symux.conf /etc/symux.conf
cp ./symon/hifn_test.layout /var/www/symon/
useradd -d /var/empty -L daemon -c 'symon Account' -s /sbin/nologin _symon
/usr/local/libexec/symon
mkdir /var/www/symon /var/www/symon/rrds /var/www/symon/rrds/localhost
#fix up symux.conf here
./symux/c_smrrds.sh all


echo > /etc/symon.conf <#
# Demo configuration for symon. See symon(8) for BNF.
#

monitor { cpu(0), mem,
if(lo0),
pf,
mbuf,
# sensor(0),
proc(sshd),
if(em0),
io(wd0)
} stream to 127.0.0.1 2100
EOF


echo > /etc/symux.conf <#
mux 127.0.0.1 2100
source 127.0.0.1 {
accept { cpu(0), mem, pf,
if(em0),
if(lo0),
io(wd0),
df(sd0a) }

datadir "/var/www/symon/rrds/localhost"
}
EOF

Thursday, June 17, 2010

regex for IP addresses

ifconfig | sed -n ‘/^[A-Za-z0-9]/ {N;/dr:/{;s/.*dr://;s/ .*//;p;}}’