Redirect and Save iptables on Ubuntu 12.04

Redirect port 8080 to 80 sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 Check iptables setting sudo iptables -t nat -L Save configure to iptables.rules sudo iptables-save > /etc/iptables.rules Save Solution #1 Configre /etc/network/interfaces iface eth0 inet dhcp pre-up iptables-restore < /etc/iptables.rules Save Solution #2 Configure /etc/network/if-pre-up.d/iptablesload #!/bin/sh iptables-restore < /etc/iptables.rules exit 0 Configure /etc/network/if-post-down.d/iptablessave #!/bin/sh iptables-save -c > /etc/iptables.rules if [ -f /etc/iptables.downrules ]; then iptables-restore < /etc/iptables....

July 5, 2013 · 1 min · oopsmonk

Connect Oracle 10g Database use JDBC

install jayDeBeApi & jpype $ sudo apt-get install python-setuptools $ sudo easy_install JayDeBeApi $ sudo easy_install jpype Download Oracle JDBC Drivers ojdbc6.jar to local. import jpype import jaydebeapi jHome = jpype.getDefaultJVMPath() print jHome jpype.startJVM(jHome, '-Djava.class.path=/path/to/ojdbc6.jar') conn = jaydebeapi.connect('oracle.jdbc.driver.OracleDriver', 'jdbc:oracle:thin:user/password@DB_HOST_IP:1521:DB_NAME') curs = conn.cursor() curs.execute("select * from ACCOUNT") acc = curs.fetchall() curs.close() conn.close() jpype.shutdownJVM() print acc Reference: https://pypi.python.org/pypi/JayDeBeApi http://wiki.python.org/moin/Oracle

June 24, 2013 · 1 min · oopsmonk

Install JDK1.4.2(32bit) on Ubuntu 12.04 LTS(64bit)

Here is an error occurred if installed directly: install.sfx.XXX: not found Solution: install g++-mltilib and JDK $ sudo apt-get install g++-multilib $ chmod +x j2sdk-1_4_2_19-linux-i586.bin $ ./j2sdk-1_4_2_19-linux-i586.bin ..... Do you agree to the above license terms? [yes or no] yes Unpacking... Checksumming... 0 0 Extracting... UnZipSFX 5.40 of 28 November 1998, by Info-ZIP (Zip-Bugs@lists.wku.edu). creating: j2sdk1.4.2_19/ creating: j2sdk1.4.2_19/jre/ creating: j2sdk1.4.2_19/jre/bin/ inflating: j2sdk1.4.2_19/jre/bin/java inflating: j2sdk1.4.2_19/jre/bin/keytool inflating: j2sdk1.4.2_19/jre/bin/policytool .... Creating j2sdk1.4.2_19/lib/tools.jar Creating j2sdk1....

June 20, 2013 · 1 min · oopsmonk

Remove the same files in two folders

有時在整理照片或文件時, 需要比對2個資料匣, 把重覆的檔案拿掉. Dwonload Source Here function usage(){ echo "Find the same file in two folders and remove it." echo "usage : ./comp-rm.sh target-dir source-dir" echo "remove the same files in target-dir." } if [ $# -ne 2 ]; then usage exit 1 fi target_dir=$1 source_dir=$2 f_list1=$(find "$target_dir" -type f) f_list2=$(find "$source_dir" -type f) for i in $f_list1; do echo $f_list2 | grep $(basename $i) >/dev/null && hit_str+=$i";" done if [ -z $hit_str ]; then echo "list is empty....

June 19, 2013 · 1 min · oopsmonk

Raspberry Pi Setup

Install Raspbian “wheezy” image Download image from Raspberry Pi offical website Mount HOME to HDD Copy HOME data to disk $ sudo mkdir /media/new_home $ sudo mount /dev/sda1 /media/new_home $ sudo rsync -aXS /home/. /media/new_home/. $ sudo umount /media/new_home fstab #get disk UUID $ sudo blkid /dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="936C-7122" TYPE="vfat" /dev/mmcblk0p2: UUID="c1198422-7a7c-4863-8a8f-45a1db26b4f2" TYPE="ext4" /dev/sda1: UUID="2cd990b5-6c27-4933-95d0-fd00b000fe77" TYPE="ext4" #modify fstab $ echo "UUID=2cd880b5-6c27-4933-95d0-fd00b000fe77 /home ext4 defaults 0 2" | sudo tee --append /etc/fstab #mount HOMW without reboot....

June 15, 2013 · 5 min · oopsmonk

Add Git SHA1 property in Apache ANT build.xml

Create git.SHA1 property in build.xml file. <available file=".git" type="dir" property="git.present"/> <target name="git.info" description="Store git info" if="git.present"> <exec executable="git" outputproperty="git.SHA1" failifexecutionfails="false" errorproperty=""> <arg value="log"/> <arg value="--pretty=oneline"/> <arg value="-n1"/> </exec> <condition property="git.version" value="${git.SHA1}" else="unknown"> <and> <isset property="git.SHA1"/> <length string="${git.SHA1}" trim="yes" length="0" when="greater"/> </and> </condition> <echo message="print git log : " /> <echo message="${git.SHA1}" /> </target> Reference: How to lookup the latest git commit hash from an ant build script

June 13, 2013 · 1 min · oopsmonk

Nginx Error - 413 Request Entity Too Large

nginx version: nginx/1.1.19, OS: Ubuntu12.04 Default nginx accepted body size limitation is 1MB. You can add client_max_body_size in nginx.conf. This parameter can put in http, server and location sections of configutation file. Enlarge body size to 10MB client_max_body_size 10M Or just disable it client_max_body_size 0 For example enlarge body size to 10MB Add to http section: $ sudo vi /etc/nginx/nginx.conf http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; client_max_body_size 10M; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime....

June 5, 2013 · 1 min · oopsmonk