2009-02-28

2009-02-26

bash - search & replace in a file using sed

Traditionally, search and replace in files have to be done in editor. But if the operation involves multiple files, it would not be practical to use editor on every files as it can be tedious (more then 5 files?) and also error prune. By using a few of bash utilities, the task can be achieve with no error and also a great opportunity to learn a few handy bash tools / command. Below is a scenario that commonly needs to be done.

Problem :
Find & replace text from a set of files


Solution :

Postgres SQL - passwordless login within bash script

Most of the time, we need to write a script to update multiple fields in a database table, pull values from database to fill up other tables or even grab from database and pass it to programs to process. The most annoying thing is every time it tries to connect to the database server, it prompts for password. Worse, if the sql statement in the bash script is not optimized or written properly, the scripts could actually ask for the password, more then 1 time !!!

Problem :

Connecting to postgresql (psql) within a bash script with no password,  preferred.


Solution :

2009-02-24

bash - output all to file

Writing script might not be only wants to shows the result on the screen. Some times, we want the script to output to a file. Not only result, but also the errors. Result of cause we want to the know, but errors is valuable also, when we need it to debug the script. Or even warn us of some thing in between the commands is having error, worse, symptoms of system / program failure.

Problem :

Pipe or output all error or status to a file


Solution :

Mascots - all of em'

Ever doing some presentation or writing a blog post and need to bring out the contents by displaying a picture of the related topic? After all, a picture worth more then a thousand words. Wiki have a list of mascot, with logo picture. :p

Adiós !!!

2009-02-23

Plugins for Apple Mail email client

Ever wonder why firefox have tons have tons of plugins to enhance the user experience? Thunder wasn't left out also.

Hey, Apple Mail also got its contributors which aims to make your life easier. The site Hawk Wings have a large collection of Apple Mail client plugins, links with short description. e.g. iCal, Address Book, Notification, Integration with other apps, Spam Tools, Interface tweaks, Archiving & others ... Check it out Hawk Wings ...

Sayonara !!!

Apple mac OS X tiger 10.4 isync plugin for nokia E71 & E63

Just bought a Nokia E series smart phone that runs symbian OS. It is able to sync with Apple mac OS X 10.4 tiger isync & ical application. But during the isync with nokia E71 or E63, it complain about not recognizing the new nokia E63 or nokia E71? No worries, it is just a few click away to download the driver for it. (Surprisingly nokia-asia.com does not have the driver, but europe.nokia.com has it)

Problem :
iSync does not recognize nokia E63 or nokia E71 after "Add Device" to sync, using bluetooth.


Solution :

2009-02-22

Wordpress - insert blank line

Having WYSIWYG in wordpress is definitely a great plus for bloggers. At least myself don't have to mess with the codes. Bold, italic, image insert & other stuff. Except 1 thing, whenever an enter is pressed (create a new line or \n), it just doesn't save it. After re-visit the WYSIWYG editor, the new line is gone, vaporized, missing, not there.


Problem :
Trying to insert new (/n) or blank line in wordpress. Tried < br /> and &nbsp and it still does not work.


Solution :

2009-02-21

cron - email recipient other the root

We all use cron (this part of the world, "open source" world). But some times we wouldn't want to send the output or error messages to root, or anyone in /etc/aliases. Only to an email we trust or a normal user on the server. Cron is flexible. Thanks Vixie, Paul Vixie.


Problem :
Status of cron jobs are often sent to root of the server. Is there a way to only send to another email address other then root? or other then the aliases in /etc/aliases?


Solution :

2009-02-19

ssh persistent error "Permission denied (publickey)."

One fine day while checking up on cron backup job on the server, it recorded an error while doing a rsync to the backup storage server. All other users have no problem login onto the backup storage server, just this particular username have problem. After checking out the interactive verbose output of the attempt ssh server session, public & private key, log files, server user's credentianls, below is the solution :


Problem :
ssh to server that uses only public key authentication only persistently got,
Permission denied (publickey).
Checked log file and got,
sshd: Authentication refused: bad ownership or modes for directory 
/user/home/directory


Solution :

2009-02-18

Problem upgrading php related packages in PORTS on FreeBSD

Apache & php are a essential to any open source servers. Not just only web, but a lot of utilities / programs are running on them as well. This make them popular. Popular to target vulnerabilities. Program bugs are also less desirable if not patching them regularly. Not to mentioned the latest functionalities that will make our life easier. All in all, less user complains, more user prasing. :p


Problem :
Upgrading php prior 5.2.8 giving errors. e.g.
warning: package ‘php5-pcre-5.2.6_2′ requires ‘php5-5.2.8′, but ‘php5-pcre-5.2.6_2′ is installed


Solution :

BIND error "permission denied"

Problem :
Error found in log file,
general: error: dumping master file: master/tmp-cFRWfFf7ah: open: permission denied
while doing a "rndc", "/etc/rc.d/named restart" or "/etc/init.d/named restart".


Solution :

2009-02-17

find - files modified in period of time

Problem :
search every files recursively from the current directory that the modification time is the last 14 days with .conf extension



Solution :

2009-02-16

Reverse SSH

Problem :
SSH server / PC in a close network unable to open port 22 or ssh port for public access


Solution :

Add group(s) to user in Linux or FreeBSD

FreeBSD :
pw usermod username -G grouplist
** grouplist is a comma separated list of group to be assign to the username. Exit & login again for the group permission to take effect.


Linux :
usermod -G groupname username

Adiós !!!

Apache failed to start - httpready

Problem :
While doing one of the below :
apachectl start
apachectl restart
/usr/local/etc/rc.d/apache start
/usr/local/etc/rc.d/apache restart

an error message appear
No such file or directory: Failed to enable the 'httpready' Accept Filter


Solution :

2009-02-11

how to retrieve akismet API key --aka-- wordpress.com api key

After re-installing a new wordpress  blog, we only found out that the akismet plugin key id has lost. But without the akismet plugin key, akismet simply won't allow to activate. We could apply a new account from wordpress.com but that would render our presiously applied wordpress.com account email address useless. More over, one might only have 1 email address to spend. How do we recover it? Scroll down :