Archive for the ‘Command Line’ Category

RedHat Linux useful commands

Tuesday, December 13th, 2011

For more commands visit: http://www.yolinux.com/TUTORIALS/LinuxTutorialSysAdmin.html

Commands:

who Displays currently logged in users.
Use who -uH for idle time and terminal info.
users Show all users logged in.
w Displays currently logged in users and processes they are running.
whoami Displays user id.
groups Display groups you are part of.
Use groups user-id to display groups for a given user.
set Display all environment variables in your current environment.
id Display user and all group ids.
Use id user-id to display info for another user id.
last Listing of most recent logins by users. Show where from, date and time of login (ftp, ssh, …) Also see lastlog command.
Show last 100 logins: last -100
history Shell command to display previously entered commands.

Parsing through mysql slow query log

Monday, December 12th, 2011

mysqldumpslow — Summarize Slow Query Log Files

The MySQL slow query log contains information about queries that take a long time to execute

$ mysqldumpslow -a slow-log

Do not abstract all numbers to N and strings to 'S'.

$ mysqldumpslow -a -s c slow-log

Do not abstract all numbers to N and strings to 'S' AND sort the results by count

ls command line

Monday, December 12th, 2011

To display the long listing in a human readable format that nicely summarizes the file sizes, use:

$ ls -lah slow-log
****************************
Example output
****************************
-rwxrwxrwx 1 bloom bloom 34K Dec 12 10:24 slow-log

MySQL process continual monitor

Friday, November 25th, 2011

From Terminal:
$ mysqladmin processlist ( hit enter )

MySQL Slow Query Logging

Thursday, November 24th, 2011

Edit my.cnf
$ sudo nano /etc/my.cnf

Search for slow and you should see:
# Slow Query Log Settings
# ———————–
#log-slow-queries=/var/log/mysqllogs/slow-log
#long_query_time=5
#log-queries-not-using-indexes

Remove the # and adjust the time if needed
save the changes and retart mysql
$ /etc/init.d/mysqld restart

The files are saved to:
/var/log/mysqllogs

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

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

Force browser to go to a different domain than what is entered in address bar

Monday, November 7th, 2011

You need to edit your /etc/hosts in your computer ( Mac ) for this demonstration. If you have a Microsoft / Windows computer, please go buy a mac or use Linux.

Anyway, the way you do it is by using terminal and at the $ prompt:
$ sudo nano /etc/hosts

then add this at the bottom of the file:
127.0.0.1 www.apple.com apple.com

This will force the browser to go to your home/local directory instead of where you typed in the address bar

Apache User crontab

Monday, November 7th, 2011

crontab -u apache -e