www.pokeroconnor.com

Recursive SED Script

June6

There are often times I want to run a SED find and replace across recursive directories, and the below is a very handy script to do so, from this excellent resource. There’s plenty of other variations of it there too.


#SR does global replacement in html files, replacing its first parameter by
#its second parameter--use with extreme caution!

find ./ -name '*.html' -print | while read i
do
sed "s/$1/$2/g" $i >$i.bak && mv $i.bak $i
done

To use this, simply execute the command via:

./SR term_to_find term_to_replace_with

As a slight tweak, and what I find more useful, is to add a third input param, for example to switch on the file names you want to replace:

#SR does global replacement in files specified in STDIN as third parameter, replacing its first parameter by
#its second parameter--use with extreme caution!

find ./ -name "*.$3" -print | while read i
do
sed "s/$1/$2/g" $i >$i.bak && mv $i.bak $i
done

For example, to replace image1.jpg with image2.jpg, in all css files, run this:

./SR image1.jpg image2.jpg css

//

Linux Boot Issue Module Not Found

March28

This is a common issue on Dell and HP laptops apparently, and is not a Windows issue per se.

For me, it happened on a Dell machine, and it is incredibly annoying.

So, if you have enabled dual-booting, with say a Windows and Linux partition, all seems fine booting into your Ubuntu install, until that is, you boot up Windows, and then try to subsequently boot up your machine to either Windows or Linux.

What happens is a message:

module name not found, press any key

Of course pressing the “any key” does nothing, and you are unable to boot up any OS from the HDD.

There are a series of excellent links on this, all worth a look, as your situation may have slight differences to some mentioned scenarios within the links below:

  • http://ubuntuforums.org/showthread.php?t=1501591
  • http://ubuntuforums.org/showthread.php?t=1560177
  • http://sourceforge.net/apps/mediawiki/bootinfoscript/index.php?title=Boot_Problems:Windows_Writes_To_MBR
  • http://ubuntuforums.org/showthread.php?t=1343851&page=2

What is happening is that certain Dell software, e.g. Datasafe, modify the MBR, and your GRUB gets corrupted/needs to be re-installed.

Quick Solution:

As described in links above, for a quick fix to allow you boot in again, load up your Live CD, e.g. ubuntu install CD you can download easily (using a Knoppix boot for example from the CD drive), and run from the CD drive. Then, open a terminal shell, and do the following:

sudo mount /dev/sda3 /mnt
sudo grub-install –recheck –root-directory=/mnt /dev/sda

In the above, sda3 represents whatever partition your Linux install is on, so will likely be different for you – that should be the only thing you need to change above.

Once done, you can boot up again as per usual, until of course you log into Windows again!

So long-term solution is to identify all Dell proprietary software (most listed in links above and http://download.cnet.com/ccleaner/ and http://forum.notebookreview.com/dell-xps-studio-xps/406492-how-do-i-remove-dells-datasafe.html), fully delete them using CC Cleaner for example, re-boot using the Live CD GRUB trick one final time, and then you should be good!

 

//

Ubuntu Restore Panels

March28

Running Ubuntu 10.10, and I accidentally deleted the panel (strip of information toolbar at the top of the screen).

To get it back, just do as described here, but watching out for the typos in the commands as printed there, namely:

gconftool –recursive-unset /apps/panel

rm -rf ~/.gconf/apps/panel

pkill gnome-panel

Viola!!

//

postfix create file maildrop warning

November14

If you ever see the following in your logs,

warning: mail_queue_enter: create file maildrop/636773.1040: Permission denied

It measn postfix is not running, and you have problems!

Running
postfix check

will likely result in:

postsuper: fatal: scan_dir_push: open directory defer: Permission denied

What this means is that the permissions for postfix dirs are all screwed, most likely after a server restart (that’s when it normally happens for me at least).

You can confirm this by doing:

postfix start

and observing:

“postfix” postsuper: fatal: scan_dir_push:
open directory defer: Permission denied

To solve, run:

postfix set-permissions

You may still have to make minor permission changes, to change owner from root to postfix for the /var/lib/postfix files.

//

phpmyadmin cant create database error

November2

If you’re getting the following error in phpmyadmin when creating a new database:

#1006 – Can’t create database

The problem is that /var/lib/mysql is probably owned by root, and ALSO in the root group. It should not be.

ls -ld /var/lib/mysql probably looks like this:

drwxrwxr-x 4 root root 4096 2010-11-01 23:45 /var/lib/mysql

It should be:

drwxrwxr-x 4 root mysql 4096 2010-11-01 23:45 /var/lib/mysql

So, run

chgrp -R mysql /var/lib/mysql

and you should be able to create databases now.

//

phpmyadmin debian password protect

November1

Quick one – steps to password protect your phpmyadmin on Debian.

Good idea also to use a symlink to obfuscate the ‘phpmyadmin’ url too.

Eg. within the docroot of a site I wish to install phpmyadmin on, I would do:

cd /var/www/site

ln -s SECRET_PATH_TO_DB /usr/share/phpmyadmin/

Your phpmyadmin install is then available on site.com/SECRET_PATH_TO_DB

For the htaccess password protection, this is a very handy generator tool. The username and password you choose for the .htpasswd protection should be saved to /usr/share/phpmyadmin/.htpasswd (swap /usr/share for whatever install path you have).

//

xampp setup for mac

September15

For local development I use Xampp, which I find to be very handy. It’s really simple to and quick to setup, but there were just 2 gripes I had when setting it up that took an hour or so to fix – very annoying, so just recording them here for reference.

Firstly, the install is as easy as detailed on the official page, and the best guide I found was this excellent one.

There are a tonne of files in your /Applications/XAMPP folder, but the most usual thing is to setup a Vhost. Edit the /Applications/XAMPP/etc/extra/httpd-vhosts.conf file for that.

BUT, the first catch is you need to ensure that the following line is uncommented in the /Applications/XAMPP/etc/httpd.conf file:

Include etc/extra/httpd-xampp.conf

Gaaahhh!!!

Second gripe, your htaccess or mod_rewrite won’t work probably, so you need to make sure that AllowOverride None is changed to AllowOverride All in /Applications/XAMPP/etc/httpd.conf, e.g.

<Directory />
Options FollowSymLinks
AllowOverride All

Apart from those two minor annoyances, it was plain sailing!


//

Apache and bind steps debian

March25

Quick steps to adding a new site on your debian box – apache and bind changes are as follows:

APACHE:

1) setup your config in sites-available
e.g. /etc/apache2/sites-available/isildur1.me
Perms are

-rw-r–r– 1 root root 1.1K 2009-10-29 00:43 isildur1.me

2) a2ensite isildur1.me

3) /etc/init.d/apache2 reload

BIND:

1) 2 reverse DNS files, e.g.
199.208.33.in-addr.arpa
200.10.79.in-addr.arpa

e.g. 77              IN PTR  isildur1.me.

2) named.conf
e.g.
named.conf:zone “isildur1.me” {
named.conf:        file “/etc/bind/isildur1.me.db”;

3) forward DNS file
e.g.
isildur1.me.db

4) reload or restart bind
/etc/init.d/bind9

That’s it, then your new site, for example Isildur1 Poker God is ready.

//

RSYNC Installation Guide

March11

Here’s the best sources of info I could find on setting up RSYNC on Linux and OS X.

And two handy tips -

//

Installing IMAP SMTP Postfix Debian

February6

I run Debian Lenny, and have my bind server setup with mail.yourdomain.com. That’s my starting point, and the following is how to install and configure SMTP and IMAP, using Postfix and SASL.

On debian you need the courier-imap package, and note it runs on port 143.

apt-get install courier-imap

This is a good guide to IMAP side of things.

VIP: Support for maildir-style mailboxes needs to be added, so edit /etc/postfix/main.cf to add the following:

home_mailbox = Maildir/

SMTP

This guide rules as a starter for SMTP.

Run apt-get install postfix-tls sasl2-bin libsasl2 libsasl2-modules, and maybe apt-get install libsasl2-2 but MAKE SURE you change /etc/default/saslauthd to have the following:

START=yes
MECHANISMS=”pam”

Next file to edit is /etc/postfix/sasl/smtpd.conf (you have to create it):
pwcheck_method: saslauthd

VI: /etc/postfix/main.cf

smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes

smtpd_recipient_restrictions =
permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination

NB, back in terminal do this:

rm -r /var/run/saslauthd/
mkdir -p /var/spool/postfix/var/run/saslauthd
ln -s /var/spool/postfix/var/run/saslauthd /var/run
chgrp sasl /var/spool/postfix/var/run/saslauthd
adduser postfix sasl

Also, copy other pam group to smtp:


cd /etc/pam.d
cp other smtp

Restart and go:

/etc/init.d/postfix restart
/etc/init.d/saslauthd start

Test your config by telnet-ing in:
telnet localhost smtp
Trying 80.237.145.96…
Connected to jimmy.co.at.
Escape character is ‘^]’.
220 kitana.jimmy.co.at ESMTP Mailserver
ehlo reptile.g-tec.co.at
250-kitana.jimmy.co.at
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH NTLM LOGIN PLAIN DIGEST-MD5 CRAM-MD5
250-AUTH=NTLM LOGIN PLAIN DIGEST-MD5 CRAM-MD5
250 8BITMIME
AUTH PLAIN amltbXkAamltbXkAcmVhbC1zZWNyZXQ=
235 Authentication successful

Or maybe not successful!!!!
VIP!!!!!!!!!!! May get an error in /var/log/mail.log with “warning: SASL authentication failure: no secret in database“.

In this case you need to set up a user and pass for SASL as follows:
saslpasswd2 -f /etc/sasldb2 -u yourdomain.com paul

Another error is “warning: SASL authentication problem: unable to open Berkeley db /etc/sasldb2: No such file or directory“.

This is solved here, READ IT!

In /etc/init.d/postfix,  around line 43 there is a list of files that are copied from their real directories into the chroot. Change the line so it looks like:
FILES=”etc/localtime etc/services etc/resolv.conf etc/hosts etc/nsswitch.conf etc/sasldb2″

//
« Older Entries