Posts Tagged ‘command line’

MySQL get the current request information

Wednesday, November 23rd, 2011

To trouble shoot an overly lengthy SQL one day, I had to use this command to see what query was taken ( literally ) forever to complete.
Log into mysql via command line and run this command while the query is running

mysql > SHOW FULL PROCESSLIST\G ( hit enter )

Here is an example of the potential output:

*************************** 1. row ***************************
     Id: 14
   User: root
   Host: localhost
     db: NULL
Command: Query
   Time: 0
  State: NULL
   Info: SHOW FULL PROCESSLIST
*************************** 2. row ***************************
     Id: 16
   User: local_bloom2
   Host: localhost
     db: local_bloom2
Command: Query
   Time: 318
  State: Sending data
   Info: SELECT i.sku, sum(i.qty_ordered) quantity
                            FROM  sales_flat_order_item i,
                                  sales_flat_order o,
                                  catalog_category_product c,
                                  cataloginventory_stock_item s,
                                  catalog_category_entity_varchar v,
                                  catalog_category_entity e,
                                  catalog_product_entity_varchar pv1,
                                  eav_attribute_option_value ev1,
                                  catalog_product_entity_varchar pv2,
                                  catalog_product_entity_int pi
                            WHERE o.created_at >= adddate(CURDATE(),-14)
                            AND   o.entity_id = i.order_id
                            AND   i.product_id = s.product_id
                            AND   s.is_in_stock = 1
                            AND   i.product_id = c.product_id
                            AND   c.category_id = e.entity_id
                            AND   e.entity_id = v.entity_id
                            AND   v.attribute_id = 33
                            AND   v.value = 'Bath & Body'
                            AND   i.product_id = pv1.entity_id
                            AND   pv1.attribute_id = 641
                            AND   (pv1.value = ev1.option_id or pv1.value like concat(ev1.option_id,',%') or pv1.value like concat('%,', ev1.option_id) or pv1.value like concat('%,',ev1.option_id,',%'))
                            AND   (ev1.value = '35-54' or ev1.option_id = 85 or ev1.option_id = 90)
                            AND   i.product_id = pv2.entity_id
                            AND   ( pv2.attribute_id = 546
                            AND    ( pv2.value = ''
                            or      (exists
                                       (select null
                                        from   eav_attribute_option_value ev2
                                        where  (
                                                 ( pv2.value = ev2.option_id
                                                   or pv2.value like concat(ev2.option_id,',%')
                                                   or pv2.value like concat('%,', ev2.option_id)
                                                   or pv2.value like concat('%,',ev2.option_id,',%')
                                                 )
                                                 AND
                                                 ('Normal/Combination' like concat('%',ev2.value,'%') or ev2.option_id = 165 or ev2.option_id = 487)
                                               )
                                        )
                                      or     not exists
                                                        (select  null
                                                         from    catalog_product_entity_varchar
                                                         where   attribute_id = pv2.attribute_id
                                                         and     entity_id = i.product_id)
                                     )))
                            group by sku
                            order by 2 desc limit 5
2 rows in set (0.00 sec)

shell command to install RApache

Wednesday, November 23rd, 2011

I found this at: https://github.com/tregoning/RApache-Installer/blob/master/install-rapache.sh

#!/bin/bash -
###############################################################################
# File: install-rapache.sh
#
# Description: Script to install & setup R(Apache) on Mac OS 10.6
#
# Prerequisites: Xcode (free Xcode3 can be downloaded here: http://bit.ly/xcode3Download)
# R (Install R-2.13.0.pkg from http://cran.r-project.org/bin/macosx)
# Ensure you click ‘Customize’ and select ‘R GUI 1.40 (64-bit)’
# if your machine supports it
#
# Instructions: run this script as *ROOT*
#
# Todo: -Ability to install in 32 bit machines
# -Option to install R from source
#
# Author: JT
###############################################################################

export EXPECTED_HASH=f66641def8127efd35b76d6e32bfaa13
export ACTUAL_HASH=`MD5 -q /private/etc/apache2/httpd.conf`
export EXPECTED_USER=root
export ACTUAL_USER=`whoami`

#Checking script is being run as root
if [ "$EXPECTED_USER" != "$ACTUAL_USER" ];then
echo ”
Error: Insufficient privileges

This script needs to be run as root. Simply run:
sudo ./install-rapache.sh

exit
fi

#Checking R is installed
if [ ! -s /usr/bin/R64 ]; then
echo ”
Error: Required software is not installed in your system

R is a prerequisite for installing R(Apache)
Please install R-2.13.0.pkg from http://cran.r-project.org/bin/macosx and,
during the setup ensure you click ‘Customize’ and add the ‘R GUI 1.40 (64-bit) option
if your machine supports it’

exit
fi

#Checking Xcode is installed
if [ ! -s /Developer ]; then
echo ”
Error: Required software is not installed in your system

Please install Xcode.
Note: Xcode 3 can be downloaded for free here: http://bit.ly/xcode3Download

exit
fi

#Installing required Apache2 library: libapreq2
cd /tmp
curl -O http://apache.mirrors.timporter.net/httpd/libapreq/libapreq2-2.13.tar.gz
tar xzvf libapreq2-2.13.tar.gz
cd libapreq2-2.13
./configure
make
sudo make install

#Installing R(Apache)
cd /tmp
curl -O http://biostat.mc.vanderbilt.edu/svn/rapache/web/files/rapache-1.1.14.tar.gz
tar xzvf rapache-1.1.14.tar.gz
cd rapache-1.1.14
./configure –with-apache2-apxs=/usr/sbin/apxs –with-R=/usr/bin/R64
sudo make
sudo make install

#Editing httpd.conf
if [ "$EXPECTED_HASH" == "$ACTUAL_HASH" ];

then
cp /private/etc/apache2/httpd.conf /private/etc/apache2/httpd.conf_bk

sed -i ” -e ’118i\
LoadModule R_module libexec/apache2/mod_R.so’ /private/etc/apache2/httpd.conf

sed -i ” -e ’119i\
ROutputErrors’ /private/etc/apache2/httpd.conf

else
echo ”
########################################################################################
** MANUAL STEP **
It looks like you have been tinkering with Apache’s config, as a result you will have to
manually add the two lines below after your last ‘LoadModule’ entry in your httpd.conf
file (/private/etc/apache2/httpd.conf)

—–COPY STARTS—–
LoadModule R_module libexec/apache2/mod_R.so
ROutputErrors
—– COPY ENDS —–

When you are done bounce Apache:
sudo apachectl restart

And check the R(Apache) info page

http://localhost/RApacheInfo

########################################################################################”
fi

echo ‘
# Required for report about R running within Apache

SetHandler r-info
SetHandler r-script
RHandler sys.source
‘ >> /private/etc/apache2/httpd.conf

#Bounce Apache and open demo page if installation was automated
if [ "$EXPECTED_HASH" == "$ACTUAL_HASH" ];
then
#Restart Apache
sudo apachectl restart

#Open Browser with info page
open http://localhost/RApacheInfo
fi

httpd.conf for Mac OSX Apache config file location

Monday, November 21st, 2011

$ sudo nano /etc/apache2/httpd.conf

Add sites to local installation of apache on mac

Tuesday, November 15th, 2011

$ nano /etc/apache2/extra/httpd-vhosts.conf
add to the bottom of the page

Edit the /etc/hosts

$ sudo nano /etc/hosts

Make the changes needed

Restart Redhat/linux from command line

Monday, November 14th, 2011

$ /sbin/shutdown -r now ( hit enter )

Apache User crontab

Monday, November 7th, 2011

crontab -u apache -e

Show files only, not . and .. using command line

Tuesday, October 25th, 2011

$ ll -h
total 7.2M
-rwxrwxrwx 1 bloom bloom 6.9M Oct 25 10:49 slow-log
-rw-rw-r– 1 bloom bloom 165K Oct 25 10:10 slow-log.oct_25_2011
-rw-r–r– 1 root root 127K Aug 3 17:16 slow-log.original

To validate that the server SSL certificate is valid or not

Wednesday, October 19th, 2011

curl -Iv https://www.bloom.com

Install LAMP on Ubuntu 11.10

Monday, October 17th, 2011

Run this in terminal to install Apache, MySQL and PHP:
$ sudo apt-get install lamp-server^ ( hit enter )

Make /var/www writable to all in terminal type this command:
$ sudo chmod -R 777 /var/www ( hit enter )

Restart Apache to activate PHP, in terminal run this command:
$ sudo /etc/init.d/apache2 restart ( hit enter )

If you want to test out if PHP is ready and running, in terminal:
$ touch /var/www/test.php

That will create a file called test.php in /var/www/
Now, edit that file using terminal enter this command:
$ nano /var/www/test.php ( hit enter )

This will open up an editor called nano, you can use VI or any other editor.

enter this:
phpinfo();
?>

Then you need to save it, so you hold down the control button, and then hit the LETTER O, then hit enter again to save it as the same name file. Then to close you hold down the control button again and hit the LETTER X.

Download phpmyadmin from sourceforge and unzip it into /var/www/ I had to rename it to just phpmyadmin instead of the current release name ( so I could remember it ).

Setting up PHPUnit on Mac

Tuesday, October 11th, 2011

All you need to do AFTER you install pear is run two commands via command line:
$ pear config-set auto_discover 1 ( hit enter )
$ pear install pear.phpunit.de/PHPUnit ( hit enter )

Thats it!