Tuesday, February 25, 2014

wget with authentication

How to use wget with authentication:

syntax:
wget --user=username --ask-password URL

example:
wget --user=lui --ask-password  http://asteriskopensourcev2.blogspot.com/sample.zip

Password for user `lui': *********

Done! You will now be able to download.




Tuesday, February 11, 2014

Magento delete unused image script

Magento delete unused image script

http://pastebin.com/ysvz6GX2

#!/bin/bash
#modified by John Louis C. Garcia on Feb. 12, 2014
#original source by Pieter at http://www.rapidcommerce.eu/blog/2012/08/remove-unused-magento-product-images/#comment-14649
#works with remote database hostname
#works also if you have cache(memcached/apc) enabled on local.xml

#instruction: change the MAGENTO_PATH.


MAGENTO_PATH="/var/www/magento"

LOG=${MAGENTO_PATH}/var/log/imagecleanup.log
DB_USER=$(sed -n 's|<username><\!\[CDATA\[\(.*\)\]\]></username>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ')
DB_PASS=$(sed -n 's|<password><\!\[CDATA\[\(.*\)\]\]></password>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ')
DB_NAME=$(sed -n 's|<dbname><\!\[CDATA\[\(.*\)\]\]></dbname>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ')
DB_PREFIX=$(sed -n 's|<table_prefix><\!\[CDATA\[\(.*\)\]\]></table_prefix>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ')
DB_REMOTEHOST=$(sed -n 's|<host><\!\[CDATA\[\(.*\)\]\]></host>|\1|p' ${MAGENTO_PATH}/app/etc/local.xml | tr -d ' ' | awk 'END{print}')
function search_db() {
        COUNT=$(mysql -u ${DB_USER} -p${DB_PASS} -h ${DB_REMOTEHOST} ${DB_NAME} --execute="SELECT count(*) FROM ${DB_PREFIX}catalog_product_entity_media_gallery WHERE value = \"$1\"")
        echo $(echo ${COUNT} | cut -d" " -f2)
}

echo "Starting image cleanup " $(date) | tee -a ${LOG}

IMG_PATH=${MAGENTO_PATH}/media/catalog/product/
for IMG in $(find ${IMG_PATH} -name '*.jpg' ! -path '*cache*' ! -name 'google*'); do
        REL_IMG=/${IMG:${#IMG_PATH}}
        if [ $(search_db ${REL_IMG/'${MAGENTO_PATH}/media/catalog/product'/}) != 1 ]; then
                IMG=${IMG##*/}
                for CACHE_IMG in $(find ${MAGENTO_PATH}/media/catalog/product/ -name "${IMG}"); do
                        echo "Found unused image ${CACHE_IMG}"
                        if [ "$1" ] && [ $1 == 'cleanup' ]; then
                                echo "Removing unused image ${CACHE_IMG}" | tee -a ${LOG}
                                rm "${CACHE_IMG}"
                        fi
                done
        else
                echo "Not touching " ${IMG}
        fi
done
echo "Finished image cleanup " $(date) | tee -a ${LOG}


exit 0;



Friday, January 10, 2014

How to use Screen in Linux

What is Screen?
- screen is an application in linux that can be used to create remote connection even if you got network interruptions.
- the windows equivalent of screen is remote desktop


Create a Screen Session

$ screen


Resume a Screen Session

$ screen -r [nameofscreen]
ex. screen -r 888911823


List all Screen Session
$ screen -ls
ex. screen -ls

888911823      (01/10/14 15:51:19)     (Attached)
888911824      (01/10/14 15:59:19)     (Attached)


Terminate a Screen Session

$ screen -X -S [nameofscreen] quit

Wednesday, November 20, 2013

Installing Debian Wheezy in Amazon EC2

Installing Debian Wheezy in Amazon EC2

1. Go to the website of debian and look for the official AMIs.

https://wiki.debian.org/Cloud/AmazonEC2Image/Wheezy#A7.2


2. Get the AMI that you want and use it in ec2.

Example: ami-537f1b52


3. Go to the AMI and enter the ami id above in the search field.


4. Select the AMI and click Launch.



* Configure your instance on how you want it to be.

5. Once launched. Go to your Instances tab, select the instance, right-click then click on start.


6. To Connect to your running instance, follow the instructions below.

To access your instance:

Open an SSH client. (find out how to connect using PuTTY)

Locate your private key file (yourkeypair.pem). The wizard automatically detects the key you used to launch the instance.

Your key must not be publicly viewable for SSH to work. Use this command if needed:
chmod 400 yourkeypair.pem

Connect to your instance using its Public DNS:
ec2-12-123-45-67.ap-northeast-1.compute.amazonaws.com

Example:
ssh -i yourkeypair.pem admin@ec2-12-123-45-67.ap-northeast-1.compute.amazonaws.com




Tuesday, July 30, 2013

Debian Wheezy Sources.list (Debian 7)

In a network installation of Debian Wheezy (Debian 7), you need to update your packages or dependencies.

To do this, I listed the following lines.


#edit sources.list file
nano /etc/apt/sources.list

#insert the following lines
deb http://ftp.us.debian.org/debian/ wheezy main
deb-src http://ftp.us.debian.org/debian/ wheezy main

deb http://security.debian.org/debian-security wheezy/updates main contrib non-free

deb http://ftp.us.debian.org/debian/ wheezy-updates main
deb-src http://ftp.us.debian.org/debian/ wheezy-updates main

#update your sources
apt-get update



-----output-------
root@debian7:~# apt-get update
Get:1 http://security.debian.org wheezy/updates Release.gpg [836 B]
Get:2 http://security.debian.org wheezy/updates Release [102 kB]
Hit http://http.debian.net wheezy Release.gpg
Hit http://http.debian.net wheezy-updates Release.gpg
Get:3 http://security.debian.org wheezy/updates/main amd64 Packages [92.5 kB]
Hit http://http.debian.net wheezy Release
Hit http://http.debian.net wheezy-updates Release
Get:4 http://security.debian.org wheezy/updates/contrib amd64 Packages [14 B]
Hit http://http.debian.net wheezy/main Sources
Get:5 http://security.debian.org wheezy/updates/non-free amd64 Packages [14 B]
Hit http://http.debian.net wheezy/main amd64 Packages
Get:6 http://security.debian.org wheezy/updates/contrib Translation-en [14 B]
Hit http://http.debian.net wheezy/main Translation-en
Get:7 http://security.debian.org wheezy/updates/main Translation-en [53.3 kB]
Hit http://http.debian.net wheezy-updates/main Sources
Get:8 http://security.debian.org wheezy/updates/non-free Translation-en [14 B]
Hit http://http.debian.net wheezy-updates/main amd64 Packages
Ign http://http.debian.net wheezy-updates/main Translation-en
Fetched 249 kB in 4s (55.4 kB/s)
Reading package lists... Done
-----output-------

Thursday, April 11, 2013

Join the VOIP & Tell!: Voip Users Conference.

Asterisk 12 Preview and you can get a chance to interact with Digium's Asterisk Leader of Development Team.

Friday April 12th at 12 Noon EDT


Monday, April 8, 2013

MD5 asterisk encryption

How to secure your passwords in your sip.conf / users.conf?



Linux Console:

Syntax: echo -n "<user>:<realm>:<secret>" | md5sum

Example:
$ echo -n "9001:asterisk:testpass123" | md5sum
cd9fc062abcc415c6505cbbe07ec18de  -



SIP.conf / USERS.conf
# add the following in your extension
md5secret="your md5 generated password from above"

Example:
md5secret=cd9fc062abcc415c6505cbbe07ec18de