Thursday, February 24, 2011

shell script variables assignment

lastfile=`tail -n 1 mysql-bin.index`
echo $lastfile

mysql backup a table / duplicate a table

mysql> create table compounds_201110223 like compounds;
Query OK, 0 rows affected (0.00 sec)

mysql> insert compounds_201110223 select * from compounds;

Wednesday, February 23, 2011

mysql insert ignore on duplicate key

INSERT IGNORE INTO all_cas (CAS, sid, source)
( SELECT DISTINCT(cas), mid, 4 FROM chemmolpharm.compounds WHERE cas REGEXP '[0-9]{2,7}-[0-9]{1,2}-[0-9]{1}' );

mysql update comments to table

ALTER TABLE all_cas COMMENT='source 1 aaa 2 ChemMol.com' ;

mysql "ERROR 1018 (HY000): Can't read dir of '.' (errno: 13)"

issue:

mysql "ERROR 1018 (HY000): Can't read dir of '.' (errno: 13)"

Solution
Restart mysql server
root@cm-test:~# service mysql stop
root@cm-test:~# service mysql start

ls ll with regular express

#!/bin/bash

for f in $(ls | egrep 'mysql-bin.0[0-9]{5}$')
do
echo "process file: $f"
done



[root@localhost recovery]# ll mysql-bin.0[0-9][0-9][0-9][0-9][0-9]
-rw-r----- 1 root root 23022429 Feb 23 06:13 mysql-bin.000001
-rw-r----- 1 root root 456769 Feb 23 06:13 mysql-bin.000002
-rw-r----- 1 root root 47295 Feb 23 06:13 mysql-bin.000003
-rw-r----- 1 root root 679680 Feb 23 06:13 mysql-bin.000004
-rw-r----- 1 root root 1742441 Feb 23 06:13 mysql-bin.000005
-rw-r----- 1 root root 5671825 Feb 23 06:13 mysql-bin.000006
-rw-r----- 1 root root 5588178 Feb 23 06:13 mysql-bin.000007
-rw-r----- 1 root root 5312684 Feb 23 06:13 mysql-bin.000008
-rw-r----- 1 root root 5569825 Feb 23 06:13 mysql-bin.000009
-rw-r----- 1 root root 5653535 Feb 23 06:13 mysql-bin.000010
-rw-r----- 1 root root 5361382 Feb 23 06:13 mysql-bin.000011
-rw-r----- 1 root root 5722384 Feb 23 06:13 mysql-bin.000012
-rw-r----- 1 root root 5759352 Feb 23 06:13 mysql-bin.000013
-rw-r----- 1 root root 6006372 Feb 23 06:13 mysql-bin.000014
-rw-r----- 1 root root 5645165 Feb 23 06:13 mysql-bin.000015
-rw-r----- 1 root root 5508167 Feb 23 06:13 mysql-bin.000016
-rw-r----- 1 root root 6258305 Feb 23 06:13 mysql-bin.000017
-rw-r----- 1 root root 5959473 Feb 23 06:13 mysql-bin.000018
-rw-r----- 1 root root 5743501 Feb 23 06:13 mysql-bin.000019
-rw-r----- 1 root root 5618976 Feb 23 06:13 mysql-bin.000020
-rw-r----- 1 root root 4157667 Feb 23 06:13 mysql-bin.000021
[root@localhost recovery]# ll | egrep "mysql-bin.0[0-9]{5}$"
-rw-r----- 1 root root 23022429 Feb 23 06:13 mysql-bin.000001
-rw-r----- 1 root root 456769 Feb 23 06:13 mysql-bin.000002
-rw-r----- 1 root root 47295 Feb 23 06:13 mysql-bin.000003
-rw-r----- 1 root root 679680 Feb 23 06:13 mysql-bin.000004
-rw-r----- 1 root root 1742441 Feb 23 06:13 mysql-bin.000005
-rw-r----- 1 root root 5671825 Feb 23 06:13 mysql-bin.000006
-rw-r----- 1 root root 5588178 Feb 23 06:13 mysql-bin.000007
-rw-r----- 1 root root 5312684 Feb 23 06:13 mysql-bin.000008
-rw-r----- 1 root root 5569825 Feb 23 06:13 mysql-bin.000009
-rw-r----- 1 root root 5653535 Feb 23 06:13 mysql-bin.000010
-rw-r----- 1 root root 5361382 Feb 23 06:13 mysql-bin.000011
-rw-r----- 1 root root 5722384 Feb 23 06:13 mysql-bin.000012
-rw-r----- 1 root root 5759352 Feb 23 06:13 mysql-bin.000013
-rw-r----- 1 root root 6006372 Feb 23 06:13 mysql-bin.000014
-rw-r----- 1 root root 5645165 Feb 23 06:13 mysql-bin.000015
-rw-r----- 1 root root 5508167 Feb 23 06:13 mysql-bin.000016
-rw-r----- 1 root root 6258305 Feb 23 06:13 mysql-bin.000017
-rw-r----- 1 root root 5959473 Feb 23 06:13 mysql-bin.000018
-rw-r----- 1 root root 5743501 Feb 23 06:13 mysql-bin.000019
-rw-r----- 1 root root 5618976 Feb 23 06:13 mysql-bin.000020
-rw-r----- 1 root root 4157667 Feb 23 06:13 mysql-bin.000021

mysql show variables

mysql> show variables like '%bin%';
+-----------------------------------------+------------+
| Variable_name | Value |
+-----------------------------------------+------------+
| binlog_cache_size | 32768 |
| binlog_direct_non_transactional_updates | OFF |
| binlog_format | MIXED |
| innodb_locks_unsafe_for_binlog | OFF |
| log_bin | ON |
| log_bin_trust_function_creators | OFF |
| log_bin_trust_routine_creators | OFF |
| max_binlog_cache_size | 4294963200 |
| max_binlog_size | 1073741824 |
| sql_log_bin | ON |
| sync_binlog | 0 |
+-----------------------------------------+------------+
11 rows in set (0.00 sec)

mysql truncate multiple tables

mysql> select concat('TRUNCATE TABLE ', TABLE_NAME, ';') from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='amp';

centos update path

echo 'export PATH=$PATH:/sbin' >> $HOME/.bash_profile

How to create a Directory with permission of drwxrwxrwt

t mean Sticky bit. It was used to trigger process to "stick" in memory after it is finished, now this usage is obsolete. Currently its use is system dependant and it is mostly used to suppress deletion of the files that belong to other users in the folder where you have "write" access to.

chmod +t mydir

Tuesday, February 22, 2011

passive nic config in redhat

[root@localhost testtcpreply]# vim /etc/sysconfig/network-scripts/ifcfg-eth1

# Broadcom Corporation NetXtreme BCM5721 Gigabit Ethernet PCI Express
DEVICE=eth1
BOOTPROTO=none
HWADDR=00:22:19:D5:28:B4
ONBOOT=yes
#NETMASK=255.255.255.0
#IPADDR=192.168.0.102
#GATEWAY=192.168.0.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes

Tuesday, February 15, 2011

mysql add enum column

mysql> alter table user_cart add cart_type enum('favorite','order') DEFAULT 'favorite';

mysql> alter table user_cart add add_time timestamp not null default CURRENT_TIMESTAMP;

Thursday, February 10, 2011

Cannot connect to a remote CD-ROM drive using VMware Infrastructure Client

To access a remote CD-ROM drive, VI Client must have the correct permissions.

To assign the correct permission to VI Client:

1. Right-click the VI Client shortcut and click Properties.
2. Click the Emulation or Compatibility tab.
3. Select Run this program as Administrator.
4. Click OK.

Acute accent in programming

` Acute accent
'
"

[root@localhost ~]# echo `date`
Thu Feb 10 07:29:41 EST 2011
[root@localhost ~]# echo "date"
date
[root@localhost ~]# echo 'date'
date
[root@localhost ~]# echo "$date"

[root@localhost ~]# echo '$date'
$date
[root@localhost ~]# echo date
date

regular express not

[^0-9a-zA-Z\-\<\>\ \:\'\=\/\?\.\,\"\@\\r\\n\(\)]

[^0-9a-zA-Z\-\<\>\ \:\'\=\/\?\.\,\"\@\\r\\n\(\)\t\{\}]

Wednesday, February 9, 2011

replace text in single or multiple files

1, replace all aaaa to bbbbb in file 1.xml

root@li9:/var/htdocs/sitemaps# sed -i 's/aaaa/bbbbb/g' 1.xml

2 replace all aaaa to bbbbb in files *.xml
root@li9:/var/htdocs/sitemaps# sed -i 's/2011-02-02/2011-02-09/g' *.xml


* -i : sed will directly modify the file if it finds anything to replace
* s : substitute the following text
* g : global, match all occurrences in the line

Tuesday, February 8, 2011

You don't have permission to access - redhat

Issue: Couldn't display some file under www folder

Soulution:
Disable selinux

[root@localhost ~]# vim /etc/selinux/config
# disabled - SELinux is fully disabled.
#SELINUX=enforcing
SELINUX=disabled

Monday, February 7, 2011

Installing PHP > 5.2.X on CentOS 5 using yum

1, import testing repository key
rpm --import http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing

2 download CentOS testing repoitory
cd /etc/yum.repos.d/
wget http://dev.centos.org/centos/5/CentOS-Testing.repo

3 install or update
update: yum --disablerepo=* --enablerepo=c5-testing update php
or fresh install: yum --disablerepo=* --enablerepo=c5-testing install php

4, restart httpd
/etc/init.d/httpd stop
/etc/init.d/httpd start

Friday, February 4, 2011

How can I rename table names in mysql

mysql> rename table sas to sds;

mysql create table command line

CREATE TABLE suppas (id int(15) NOT NULL auto_increment, su_id int(12) default NULL, c_id int(12) default NULL, PRIMARY KEY (id) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;

Wednesday, February 2, 2011

linux sort a file

greg@SS:/site# sort cas.txt > cas2.txt

linux get file line number

greg@SS:/site# wc -l cas.txt
3725 cas.txt

grep regular expression space

greg@SS:/site# less APAC.txt | grep '[0-9]\{2,7\}-[0-9]\{1,2\}-[0-9]\{1\}' > abc.txt

greg@test:/test$ less filtered.txt | grep "^[0-9]\{1,10\}[[:space:]]\{1,20\}[0-9]\{2,7\}-[0-9][0-9]-[0-9]$" > filtered.txt1

html redirect

Add this line in your homepage header: 




<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/">