Archive

Archive for December, 2008

Create Apache2 self sign cert

December 29th, 2008

$ openssl genrsa -des3 -out server.key 1024

$ openssl rsa -in server.key -out server.key.insecure

$ openssl req -new -key server.key -out server.csr

$ openssl req -noout -text -in server.csr

$ sudo openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

$ sudo mv server.crt /etc/ssl/certs
$ sudo mv server.key.insecure /etc/ssl/private/server.key
$ sudo mv server.key /etc/ssl/private/server.key.secure

$ openssl s_client -connect pse02:443

Add :443 and SSL cert info to file

$ cat /etc/apache2/sites-available/default
NameVirtualHost *:443

ServerName server.name
ServerAdmin email@host.com

SSLEngine On
SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key

Apache, Uncategorized

Python: Working with Lists

December 29th, 2008

LIST ARE DYNAMIC.

def list():
items=[]
i=0
while i<=5:
items.append(i)
i+=1
return items

a=list()

print a

$ python test.py
[0, 1, 2, 3, 4, 5]

Python

Python: Return variables from a function example.

December 26th, 2008
#!/usr/bin/python
def test():
      a="hello"
      b="no"
      return a,b
print test()
>['hello','no']
a=test()
print a[0]
>hello
print a[1]
>no

Python

Dell M1530 XPS Touchpad problems w/ Ubuntu

December 18th, 2008

add i8042.nomux=1 to /boot/grub/menu.lst like this:

title Ubuntu intrepid (development branch), kernel 2.6.26-5-generic
root (hd0,7)
kernel /boot/vmlinuz-2.6.26-5-generic root=UUID=3ce50c52-edc5-4c07-ac1f-3e189a0f8163 ro quiet splash i8042.nomux=1
initrd /boot/initrd.img-2.6.26-5-generic
quiet

Ubuntu

Getting Airport Express working with Xbox 360

December 13th, 2008

Problem: I have an airport express in my basement but my xbox is located upstairs. I want to avoid running wire upstairs as well as purchasing the $80 wireless adapter for the xbox. Since i have a spare airport express i want to set this up in brigding mode. It does work but there are quite a few steps. See below:

How to configure airport xpress with Xbox

  1. Setup main base station to work correctly
  2. Set channel to ‘1′ or the same on both.
  3. Get the airport id from each wireless unit (not the WAN id) - you will need this later.
  4. On the airport for the xbox make sure you have these settings;
  5. Wireless Mode: Create Wiresless Network (home router)
  6. Connect using: Airport (WDS)
  7. Mac Address: (enter the mac for the main base station)
  8. Configure: Using DHCP
  9. Under WDS Table
  10. enable this base sataion as ‘remote base stations’
  11. Enter airport ID for main base station.
  12. On the main base station go to the WDS tab
  13. enable as main base station
  14. add mac address of xbox airport express

Update both and restart!

Networking, Uncategorized

Insert multiple records in MySQL with one Stmt.

December 11th, 2008
INSERT INTO table (id, name) values ('1','test');
INSERT INTO table (id, name) values ('2','test2');
INSERT INTO table (id, name) values ('3','test3');

However, it is much quicker to do it this way:

INSERT INTO table (id, name) values ('1', 'test1'), ('2', 'test2'), ('3', 'test3');

Much faster!

Uncategorized, mysql

Get IP Address in Python on Linux

December 5th, 2008
#!/usr/bin/python

import socket
import fcntl
import struct

def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(
        s.fileno(),
        0x8915,  # SIOCGIFADDR
        struct.pack('256s', ifname[:15])
    )[20:24])

print get_ip_address(’lo’)
print get_ip_address(’eth0′)

Uncategorized

Sending mail in Python

December 5th, 2008
#Sample function to send mail in python

import smtplib
from email.mime.text import MIMEText #need this for subject line in email

def send_mail(mail_message):

        smtpserver='smtpserver.com'
        host = socket.gethostname()

        RECIPIENTS = ['email@host.com']
        SENDER = ‘root@%s.host.com’ % host
        MESSAGE = “”"Subject: [Nagios] Loadscript Errors
From: nagios@%s.host.com

%s
“”" % (host, mail_message)

        session = smtplib.SMTP(smtpserver)
        smtpresult = session.sendmail(SENDER, RECIPIENTS, MESSAGE)

        session.close()

Python

Rsync - How to backup your server the right way!

December 4th, 2008

Describe How to Set Up Rsync here.install rsync on both client and server. they should have the same versions of rsync installed.

$apt-get install rsync

Create new ssh key w/out password

$ssh-keygen -f rsync_key -C 'Rsync Key' -N '' -t rsa -q

copy key to server

ssh-copy-id -i /home/user/.ssh/rsync_key.pub jesterj@server
jesterj@server's password:
Now try logging into the machine, with "ssh 'jesterj@server'", and check in:

  .ssh/authorized_keys

test login with specified key

slogin -i ~/.ssh/rsync_key backupuser@server1

Make sure rsync is running.

/etc/init.d/rsync start

Test from local machine to verify you can connect:

$ rsync -e ssh localhost::

Now run this command from backup server to sync files. the ‘n’ aoption does a test run. remove it to do an actual sync.

rsync -van --delete --ignore-errors -e "ssh -i /home/user/.ssh/rsync_key" /source/path jesterj@server:/backup/path
Add command to cron to repeat.

*The '--delete' means to delete items that don't exist in the backup location, --ignore-errors, continues the  backup
even though errors exist.

Uncategorized

Software RAID Setup under Ubuntu

December 3rd, 2008

install ‘mdadm’. to reconfig run ‘dpkg-reconfigure mdadm’

CREATE THE ARRAY

raid5: mdadm - -create - -force /dev/md0 - -level=raid5 - -chunk=64 - -parity=left-symmetric - -raid-devices=3 /dev/sdb /dev/sdc /dev/sdd

raiad0/Striping:  mdadm - -create /dev/md0 - -level=stripe - -chunk=4096 - -raid-devices=2 /dev/sda /dev/sdb

STOP MDADM
sudo mdadm –stop /dev/md0 (if resource busy)

CREATE PARTITION
sudo fdisk /dev/md0

FORMAT
sudo mkfs.ext3 /dev/md0

MOUNT DRIVE
mount /dev/md0 /mnt/raid

VIEW RAID DETAILS

mdadm -D /dev/md0

-add to /etc/fstab for mount on boot!
-do a ‘df’ to view your new system!

SAVE CONFIG FOR REBOOT

mdadm --detail --scan >> /etc/mdadm/mdadm.conf

Uncategorized

Python remove duplicate files script (based on md5 hash)

December 2nd, 2008
#!/usr/bin/python
# This script compares the file contents of two directories
# using and md5 hash and deletes any duplicate files from the
# target directory

import os
import md5
import sys
import base64

source={}
target={}

source_path="/home/jesterj/source"
target_path="/home/jesterj/target"

def gather_files(dir,dict):
	os.chdir(dir)
	names=os.listdir(dir)
	for filename in names:
		#read file
		f = open(filename)
		file_contents = f.read()

		#create new hash
		hash=md5.new()
		hash.update(file_contents)
		hex=hash.hexdigest()

		#add to dictionary
		dict[hex] = filename

def remove_matches():
	has_dupes=0
	for hash,file in source.iteritems():
		if target.has_key(hash):
			print “%s checksum %s exists in both dirs.” % (file, hash)
			#remove_target_file(file)
			has_dupes=True
	if has_dupes==False:
		print “No duplicate files found.”

def remove_target_file(a):
	os.chdir(target_path)
	os.system(”rm ” + a)
	print “File ” + target_path+”/”+a + ” removed”

def main():
	try:
		gather_files(source_path,source)
		gather_files(target_path,target)
		remove_matches()
	except:
		print “error”

main()

Python

Python: Dictionary examples.

December 2nd, 2008
#!/usr/bin/python
#dictionary
source={}

source["123"] = “filename.txt”
source["444"] = “fit”

for i,v in source.iteritems():
print “%s %s” % (i,v)

# python dict.py
123 filename.txt
444 fit

Uncategorized