SQL Show Log

#!/bin/bash
# —————————————————-
#
# SQL Show Log version 1.0
# @author Raymond S. Usbal
# @usage sqlshowlog
#
# —————————————————-

### check parameter
E_NO_ARGS=65

if [ $# -eq 0 ]
then
echo “SQL Show Log version 1.0
Usage: sqlshowlog

exit $E_NO_ARGS
fi

### get latest MySQL log
for file in mysql-bin.??????*; do FLE_LATEST=$file; done;

### build start date string
START_DTE=$(date +%Y-%m-%d\ %k:$(($(date +%M) – $1)):%S)

mysqlbinlog –start-date=”$START_DTE” $FLE_LATEST \
| grep -v ‘^[#/]‘ \
| grep -v ‘SET TIMESTAMP’ \
| grep -v ‘SET @@session’ \
| grep -v ‘DELIMITER’ \
| grep -v ‘ROLLBACK’ \
| sed ‘s/\/\*!\*\///g’

### end

Posted in Bash script | Leave a comment

Palayan City

I adopted a new home and created a website for it.  Check it out here: Palayan City

Posted in Inspirational, Made me think, Workplace, Worship | Tagged , | Leave a comment

How to create reverse traceroute page on your website using PHP

<?php
$result = exec('traceroute ' . $_SERVER["REMOTE_ADDR"], $lines);
echo '<h1>Your IP is ' . $_SERVER["REMOTE_ADDR"] . '</h1>';
echo '<pre>';
foreach ($lines as $n => $line) {
	if ($n) echo '<br />';
	echo $line;
}
echo '</pre>';
echo '<p>-end-</p>';

Here’s how the resulting page looks like: reverse-traceroute.php

Posted in Linux Administration, PHP, Programming | Tagged , , | Leave a comment

How to Convert Text File From UTF-8 to ISO-8859-1 Encoding

$ iconv --from-code=ISO-8859-1 --to-code=UTF-8 latin1.txt > utf8.txt

or simply

$ iconv -f ISO-8859-1 -t UTF-8 latin1.txt > utf8.txt

$ iconv -t ISO-8859-1 -f UTF-8 inputfile > outputfile

Posted in Linux | Tagged , , | Leave a comment

How to redirect pages to a new domain

RedirectMatch 301 (.*)$ http://www.newdomainhere.com$1

Save this into .htaccess and upload on the root directory on your old domain.

Posted in Apache2, Linux, Linux Administration | Tagged | Leave a comment

How to set a MySQL Table AUTO_INCREMENT

To start with an AUTO_INCREMENT value other than 1, you can set that value with CREATE TABLE or ALTER TABLE, like this:

mysql> ALTER TABLE tbl AUTO_INCREMENT = 100;

Posted in MySQL, SQL | Tagged | Leave a comment

Find a string in files under Subversion

As a programmer, I’ve been using find to locate string in my source code.  Issuing a find would include svn files too which is not my intension.  Here’s the command:

$ find . -not -regex '.*svn.*' -exec grep "$1" '{}' \; -print


Add multiple files to svn repository

$ svn st | grep ^? | cut -b7- | xargs svn add

Posted in subversion | Tagged , , | Leave a comment

How to Remove a MySQL Table constraint

ALTER TABLE `attributes` DROP FOREIGN KEY `attributes_ibfk_1`;

MySQL ERROR 1005 (HY000): Can’t create table ‘Table.frm’ (errno: 150).  Here’s the solution.

Example:
ALTER TABLE `race` DROP FOREIGN KEY `race_ibfk_1`;

ALTER TABLE `race`
ADD CONSTRAINT `race_ibfk_1` FOREIGN KEY (`specieId`) REFERENCES `specie` (`specieId`) ON DELETE CASCADE;

Posted in MySQL, SQL | Tagged , | Leave a comment

How to mount an .iso image file?

$ sudo mount -o loop /path/to/feisty-desktop-i386.iso /tmp/ubuntu-livecd

Posted in Linux, Linux Administration | Tagged , , | Leave a comment

How to Find and Replace a String on the command line?

This command will replace all instances of ‘replaceme’ with ‘newstring’ in files ‘*.php’ on /home/mysite/httpdocs.

find /home/mysite/httpdocs -name '*.php' | xargs replace 'replaceme' 'newstring' --

Posted in Linux, Linux Administration | Tagged , | Leave a comment