Monday, January 31, 2011

/bin/bash^M: bad interpreter: No such file or directory

-bash: ./2_genDB.sh: /bin/bash^M: bad interpreter: No such file or directory

Here is the solution:
http://www.linuxforums.org/forum/red-hat-fedora-linux/65469-bad-interpreter-no-such-file-directory.html

Quote:
#!/usr/bin/perl

die "Usage: $0 < files >\n" unless @ARGV;

for $file (@ARGV)
{
open IN, $file or die "$0: Cannot open $file for input!\n";

my @lines = <IN>;

close IN;
open OUT, "> $file" or die "$0: Cannot open $file for output!\n";

s/\r$// for @lines;
print OUT for @lines;
}

Save this file as fix_m.pl

run perl fix_m.pl yourshell.sh

check linux shell version

gregg@server:/opt/de$ echo $SHELL
/bin/bash

mysqldump no data , mysqldump a table with data

1, Dump whole DB schema
$ mysqldump --no-data -u mysqluser -pMysql_DB_PW api > api.mysql

2, Dump a table data from DB
$ mysqldump  -u mysqluser -pMysql_DB_PW  api_DB a_table  > db_table.mysql

Monday, January 24, 2011

enable htaccess

Need to update  #AllowOverride None to AllowOverride AuthConfig

<Directory "/var/www/html">

    Options Indexes FollowSymLinks

    #AllowOverride None
    AllowOverride AuthConfig

    Order allow,deny
    Allow from all


</Directory>

Sunday, January 23, 2011

mysql regular express

Tel phone number 555-555-5555

SELECT * FROM phone WHERE pnumber  REGEXP '[0-9]{3}-[0-9]{3}-[0-9]{4}';


CAS number 
SELECT * FROM products WHERE cas REGEXP '[0-9]{2,7}-[0-9]{1,2}-[0-9]{1}';


Friday, January 21, 2011

sudo: no valid sudoers sources found, quitting - ubuntu

Issue:

When I tried to add a new user into sudoer file  /etc/sudoers, I need to chmod sudoers
chmod +w /etc/sudoers
Then, system gave this error:
sudo: /etc/sudoers is mode 0640, should be 0440
sudo: no valid sudoers sources found, quitting

Solution:
Enter Ubuntu recovery mode to change /etc/sudoers to 0440

enter ubuntu recovery mode in vm

press 'shift' when reboot the ubuntu in VM

Thursday, January 20, 2011

how to embed google map in website

Recently, I just added gmap to my customer's website
http://northbeachhealth.com/contact.php

Here are instructions:
1, get a free google api key
Here is the page to get key
http://code.google.com/apis/maps/signup.html

2, find longitude and latitude of the address
A, enter your address in gmap
http://maps.google.com/maps?oe=utf-8&client=firefox-a&rlz=1R1GGLL_en___US406&q=367+Bay+St.,+Suite+B+San+Francisco,+Ca.+94133&um=1&ie=UTF-8&hq=&hnear=367+Bay+St,+San+Francisco,+CA+94133&gl=us&ei=Vpw4TdHXN8TflgfYmLmHBw&sa=X&oi=geocode_result&ct=title&resnum=1&ved=0CBMQ8gEwAA
B, click the 'link' on the right top of the map, you will see
'Paste link in email or IM' and
'Paste HTML to embed in website'

Copy the code in 'Paste HTML to embed in website'.
You will find 'll=37.805672,-122.413083', they are longitude and latitude of the address


View Larger Map



3, add these code into your html page head part.
Go to the page http://northbeachhealth.com/contact.php
right click the page and get source code from line 8 - line 40

  <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAwRhSY6F_2jelV6V3hr36IRQXzaJo3hs4ignG9MPTCEQrUyb-4RTCJR_RLSFtILRbBVU3WW33j5ikTw"
  type="text/javascript"></script>
 

    <script type="text/javascript">
    function createMarker(point,html,what)
    {
        var marker = new GMarker(point,{id:what, name:"chemmol", description:"chemalog"});
        GEvent.addListener(marker, "click", function()
        {
          marker.openInfoWindowHtml(html);
        });
        return marker;
    }
     
    function initialize()
    {
      if (GBrowserIsCompatible())
      {
            var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(37.805672,-122.413083), 16);
           
            var bz_point = new GLatLng(37.805672,-122.413083);
            var marker = createMarker(bz_point,'<div style="width:240px">BinZhi Acupuncture Clinic  <p>',"this")
            map.addOverlay(marker);     
       
            map.openInfoWindow(map.getCenter(), document.createTextNode("BinZhi Acupuncture Clinic"));
            map.setUIToDefault();
           
        }
    }

    </script>

4, in your html page body
copy
 <div id="map_canvas" style="width: 400px; height: 500px"></div>

dump mysql table to csv file

1, Login to mysql terminal:
c@cm-test:~$ mysql -u xxxxxx -pxxxxxxx mydatabase

2, run:
mysql> select * into OUTFILE 'abc.CSV' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM excel_unique;

3, the file should be in
/mydisk/lib/mysql/mydatabase/abc.CSV

Friday, January 14, 2011

Thursday, January 13, 2011

get table info

method 1:
mysql> show create table xxxxxxxxx;
+-----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| compounds | CREATE TABLE `xxxxx` (
`mol_id` int(10) NOT NULL AUTO_INCREMENT,
`uid` int(10) DEFAULT NULL,
`ucid` varchar(255) DEFAULT NULL,
`CASNumber` varchar(255) DEFAULT NULL,
`CName` varchar(255) DEFAULT NULL,
`SubstanceID` varchar(255) DEFAULT NULL,
`MF` varchar(255) DEFAULT NULL,
PRIMARY KEY (`mol_id`),
UNIQUE KEY `CAS` (`CASNumber`)
) ENGINE=MyISAM AUTO_INCREMENT=49400000 DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC |
+-----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>

method 2:
mysql> select * from information_schema.tables WHERE table_name='table_name' and TABLE_SCHEMA='db_name';

+---------------+--------------------+------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+-------------------------------------------------+---------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | ENGINE | VERSION | ROW_FORMAT | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH | INDEX_LENGTH | DATA_FREE | AUTO_INCREMENT | CREATE_TIME | UPDATE_TIME | CHECK_TIME | TABLE_COLLATION | CHECKSUM | CREATE_OPTIONS | TABLE_COMMENT |
+---------------+--------------------+------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+-------------------------------------------------+---------------+
| NULL | xxxxx | compounds | BASE TABLE | MyISAM | 10 | Dynamic | 0 | 0 | 0 | 281474976710655 | 2048 | 0 | 49400000 | 2011-01-13 16:10:20 | 2011-01-13 16:10:20 | NULL | latin1_swedish_ci | 0 | checksum=1 delay_key_write=1 row_format=DYNAMIC | |
+---------------+--------------------+------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+-------------------------------------------------+---------------+
1 row in set (0.00 sec)

mysql reset auto_increment

alter table compounds auto_increment=49400000;

Tuesday, January 11, 2011

import openssl key to tomcat

1. Generate a self-signed certificate (or CA trusted certificate if needed)
1) Generate a private key
openssl genrsa -des3 -out es.key 2048
2) Generate a CSR
openssl req -new -key es.key -out es.csr
 3) Generate a self-signed certificate
openssl x509 -req -days 3650 -in es.csr -signkey es.key -out es.crt

2, Import the SSL Ceritificate into PKCS#12 keystore:
openssl pkcs12 -export -in es.crt -inkey es.key -out es.p12 -name es_tomcat

3, list privatekeyentry
keytool -list -v -keystore es.p12 -storetype pkcs12

4,Import CA/cacert.crt into the Java cacerts, so that the tomcat install can talk to itself if needed.
keytool -import -keystore es.keystore -file es.crt

5, Covert the PKCS#12 keystore to JKS keystore
keytool -importkeystore -srckeystore es.p12 -destkeystore es.jks -srcstoretype pkcs12

keytool -list -v -keystore es.jks

6 update server.xml
vim /opt/tomcat/conf/server.xml




cat /dev/null > /opt/tomcat/logs/catalina.out
/etc/init.d/tomcat stop
cat /dev/null > /opt/tomcat/logs/catalina.out
/etc/init.d/tomcat start
less /opt/tomcat/logs/catalina.out

Friday, January 7, 2011

Thursday, January 6, 2011

clear mysql-bin log file or disable mysql bin log

Step 1,
Go to folder
/var/lib/mysql

Step 2:
Run:
[root@localhost mysql]# mysqladmin -u xxxx -pxxxx flush-logs

Mysql will create a new bin-log file - for my server it is mysql-bin.000014
-rw-rw---- 1 mysql mysql 22770974 Jan 6 04:02 mysql-bin.000011
-rw-rw---- 1 mysql mysql 79427070 Jan 6 04:04 mysql-bin.000012
-rw-rw---- 1 mysql mysql 109593 Jan 6 04:07 mysql-bin.000013
-rw-rw---- 1 mysql mysql 1318 Jan 6 04:07 mysql-bin.000014
-rw-rw---- 1 mysql mysql 266 Jan 6 04:07 mysql-bin.index

Step 3:
You can delete all mysql-bin log file except the latest one.
Here is the sample:
rm mysql-bin.000004 -f
rm mysql-bin.000005 -f
rm mysql-bin.000006 -f
rm mysql-bin.000007 -f
rm mysql-bin.00000* -f


Delete mysql bin log file older than 2 days
find /var/lib/mysql/mysql-bin.* -mtime +2 -exec rm {} \;