Saturday, December 15, 2018

SSH - No supported authentication methods available

When you setup SSH public key authentication, you may be hit by an error saying



If you are sure that your authorized_keys file at the user .ssh directory is correct, you may want to check

1. Make sure there no extra line at the end of the file
2. Make sure authorized_keys only have permission 644 and nothing more


Wednesday, November 21, 2018

Linux - Run shell script function argument as a command inside the function

My intention is to create a Linux shell script function which perform some generic calls when the command is passed into as function argument. For example


As you can see, the run() to will execute its input argument as a command and generically pipe to some log file.

The run() work fine most of the time until the command become complex, for example, piping the output (e.g. fgrep -w processor /proc/cpuinfo | wc -l).

If I run the above program, the output has some error


When I turn on shell debugging (set -x), it shows that the | is single quoted. That cause the command to treat | as literal string, and thus, the error on the fgrep call.


To workaround it, in the run(), you need to add ksh -c and double quote $@.  The fix explicitly call ksh -c and treat everything inside "$@" as literal command string. The double quote is important here. With the double quote, ksh will not escape the | character.


and it gives the proper output.



Monday, October 1, 2018

Oracle - ORACLE error 959 encountered when importing with imp


If the dump is exported with imp, you cannot use impdp and you may face issue such as


IMP-00003: ORACLE error 959 encountered
ORA-00959: tablespace 'XXXXXX' does not exist


Below are the steps to work around it

1) Create the user (Note: for simplicity, I had grant TESTER all privileges)

$ sqlplus sys as sysdba
SQL> drop user TESTER cascade;
User dropped.
SQL> create user TESTER identified by TESTER default tablespace USERS;
User created.
SQL> grant all privileges to TESTER;
Grant succeeded.
SQL> exit



2) Generate the index SQL file

$ imp tester/tester file=somedata.dmp log=somedata.log indexfile=somedata.sql full=y


3) Open the indexfile (somedata.sql) in a text editor that can do find and replace over an entire file, and issue the following find and replace statements IN ORDER (ignore the single quotes.. '):

* Find: 'REM'  Replace:
* Find: '"source_tablespace"' Replace: '"USERS"'
* Find: '...' Replace: 'REM ...'
* Find: 'CONNECT' Replace: 'REM CONNECT'

Save the indexfile

4) Perform the dump. But since TESTER is an admin, we need another admin account (some_admin_user) to import the dump

$ imp some_admin_user/some_admin_user_password file=somedata.dmp log=somedata.log grants=n fromuser=SOME_OTHER_USER touser=TESTER
. . importing table                "ABC"          8 rows imported
.....snip.....
IMP-00017: following statement failed with ORACLE error 959:
...... snip.............
CREATE TABLE "SOMETABLE"
...... snip.....
IMP-00003: ORACLE error 959 encountered
ORA-00959: tablespace 'XYZ' does not exist
....snip.........
About to enable constraints...
Import terminated successfully with warnings.


You can see that one of the table (e.g SOMETABLE) has an ORA-00959: tablespace 'XYZ' does not exist

4) Locate the problematic table in the indexfile and load it into the database. This involve manual work such as looking for the create table and alter table SQL statement in the indexFile. After locating all these SQL statement, put them into an sql file (e.g some_table.sql)

Then, run the SQL against the database

$ sqlplus some_admin_user/some_admin_user_password @some_table.sql


5) Import data to specific table


$ imp  some_admin_user/some_admin_user_password file=somedata.dmp log=somedata.log grants=n fromuser=SOME_OTHER_USER touser=TESTER tables=SOMETABLE DATA_ONLY=Y
....snip.......
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
. . importing table            "SOMETABLE "          10 rows imported
Import terminated successfully without warnings.


Tuesday, September 25, 2018

Hibernate - @Lob with PostgreSQL


In Java, if you declare

@Lob
@Column(name = "Remark")
protected String Remark;

Hibernate will generate the column as Text data type.

CREATE TABLE public.sometable
(
    id integer NOT NULL DEFAULT ,
    remark text COLLATE pg_catalog."default",
 )

Everything is good so far, however, when you query the database with select statement (e.g select * from sometable), it will show



In my test case, all remark column are empty string. So, what are those numbers? These numbers are the UID of the LOB for each remark. In order to view the original text, one may need to run


select id, convert_from(loread(
      lo_open(remark::int, x'40000'::int), x'40000'::int), 'UTF-8')
  AS remark from mission


Monday, August 27, 2018

Turning off overwrite/overtype mode

I had a little irritating problem today when I am typing in WhatApp Web. For some reason, the text in the textbox is always in overtype mode. I checked the INS key, the onscreen keyboard, etc... and nothing obvious to me. After some research, I finally figure out that pressing "CAP + INS" key together will turn on and off overtype mode. 

Tuesday, July 10, 2018

Tomcat - removing server info

Below are the steps to remove Tomcat Server Information

1. Make sure Tomcat is not running
2. Navigate to "Tomcat Installation"/lib
3. Backup catalina.jar
4. vi catalina.jar
5. select "org/apache/catalina/util/ServerInfo.properties" and remove the server info
6. Then, save the file and restart Tomcat

Sunday, June 3, 2018

Boostrap Validator - Reset validated field

If you work with Boostrap Validator (http://1000hz.github.io/bootstrap-validator/), sometime, you may 
want to reset validated field.

If you have added





You will need to remove has-error, has-danger and has-success.

For example

$('#from_group').removeClass('has-error has-danger has-success');

If you have added







You will need to remove glyphicon-remove and glyphicon-ok class

For example,

$('#glyphicon_span').removeClass('glyphicon-remove glyphicon-ok');

If you have added










You will need to empty the inner html

For example,

$('#error_div').html("");

SSH - No supported authentication methods available

When you setup SSH public key authentication, you may be hit by an error saying If you are sure that your authorized_keys file at the...