Thursday, September 27, 2018

How To Install Python3 and OCI SDK In Different Location of Linux

Requirement

Default Oracle Linux has python2 installed, right rising of python3, we would like to use python3 for new projects while no touching on existing python2 environment
Get  source cod from python official website
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
Put it to local /u02/storage

Install Extra,Configure and Make the binaries

Run as root
make -o /u01/python3
cd /u02/storage
tar xf Python-3.6.6.tar.xz
cd Python-3.6.6
yum install openssl-devel
yum install zlib-devel     ---- install zlib to avoid error 
./configure --prefix=/u01/python3
make
make install
alias pip='/u01/python3/bin/pip3'
alias python='/u01/python3/bin/python3'

Install and Config OCI SDK for Python

If your hosts are behind firewall, you need to tell python proxy details:
export https_proxy=http://www-proxy.us.test.com:80/
pip install oci 
see more details Oracle OCI SDK doc 

Output

the successful output is like:
.......
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1

Error

If you see such error
zipimport.ZipImportError: can't decompress data; zlib not available python
yum install zlib-devel    -------- to fix the zlib missing error

Sunday, September 23, 2018

Crontab Job Is Not Executed As Expected

Symptom

   We have a crontab job as below,  it does not run as expected. The /var/log/cron shows  the cron daemon has invoke it. But no log output.  Manual run is fine but not in crontab job

30 22 * * 1 /almjira_shared/monitor_scripts/lusi/atlassianlabs-lusi-aa6116a95ea3/lusi.sh /u01/app/atlassian/admin/jira/caches/indexes > /almjira_shared/monitor_scripts/lusi/atlassianlabs-lusi-aa6116a95ea3/`hostname -s`-$(date +%F_%R)-output.txt &

Solution:

   The crontab daemon can't recognize  %  in the command line.  We need to escapte % to make it work.  So the correct format is :

30 22 * * 1 /almjira_shared/monitor_scripts/lusi/atlassianlabs-lusi-aa6116a95ea3/lusi.sh /u01/app/atlassian/admin/jira/caches/indexes > /almjira_shared/monitor_scripts/lusi/atlassianlabs-lusi-aa6116a95ea3/`hostname -s`-$(date +\%F_\%R)-output.txt &

Wednesday, September 19, 2018

ORA-28014: cannot drop administrative users on Oracle 18.3

Symptom:

  We would like to drop ORDS schemas and reinstall ORDS in 18.3 DB

SQL>  drop user ORDS_PUBLIC_USER cascade;
 drop user ORDS_PUBLIC_USER cascade
*
ERROR at line 1:
ORA-28014: cannot drop administrative users

Solution:


SQL> alter session set "_oracle_script"=true;

SQL>  drop user ORDS_PUBLIC_USER cascade;

User dropped.

SQL>  drop user ORDS_METADATA  cascade;

User dropped.

Tuesday, September 18, 2018

How to Set Debug for ORDS ( Oracle Rest Data Service)

Symptom:

     We need to debug into ORDS ( Oracle Rest Data Service) to see any further error stack

Solution:

     Find defaults.xml file in ORDS home. ie /opt/ords_config_dir/ords/defaults.xml

     Add below two entry to true. Bounce ORDS, then you see the error stack on your browser.

<entry key="debug.debugger">true</entry>

<entry key="debug.printDebugToScreen">true</entry>

Monday, September 17, 2018

How To Set Env Variable in GI/CRS

Symptom:

    Sometimes we need to set env variables in CRS for Database .  For example, we need to set ORACLE_UNQNAME  for a few Databases. So each database can get its unique name from this variable. We can add other variable for different usages

Solution:

test0024!oracle (bash) /u01/app/oracle/product/12.1.0.2/dbhome_2/network/admin
testdb1% srvctl getenv database -db testdb
testdb:

test0024!oracle (bash) /u01/app/oracle/product/12.1.0.2/dbhome_2/network/admin
testdb1 % srvctl setenv database -db testdb -env "ORACLE_UNQNAME=testdb"

test0024!oracle (bash) /u01/app/oracle/product/12.1.0.2/dbhome_2/network/admin
testdb1% srvctl getenv database -db testdb
testdb:
ORACLE_UNQNAME=testdb

Thursday, September 13, 2018

Simple Python3 Script To Send a Message to Slack Channel


#!/u01/python3/bin/python3
import urllib.request
import urllib.parse
import time
# prepare your clientid, token and channelid
mesg = { 'clientid':'dkenfeewe','token':'***********','channelid':'*****','text':'' }


 def mesg2slack(mytext):
    """
    send notification mesg to slack channel
    """
    global mesg
    mesg['text']=mytext
    mesgutf = urllib.parse.urlencode(mesg).encode("utf-8")
    slackurl = 'https://test.test.com/push.message'
    req = urllib.request.Request(slackurl, data=mesgutf) # this will make the method "POST"
    resp = urllib.request.urlopen(req)

 mesg2slack( 'Weekly Jira UAT bounce ' +  time.strftime('%D %H:%M:%S',start_time) )
 

Wednesday, September 12, 2018

Concat&Limit Slight Difference Between Oracle and Mysql


CONCAT

Oracle:

select concat(b.pkey, concat('-', a.issuenum)) as PKEY from jira.jiraissue a join jira.project b on a.project = b.id where a.id in (xxxx,xxxx);


Mysql:

select concat(b.pkey, '-', a.issuenum) as PKEY from jira.jiraissue a join jira.project b on a.project = b.id where a.id in (xxxx,xxxx);

LIMIT

Oracle:

SELECT ID, UPDATED FROM JIRA.JIRAISSUE ORDER BY UPDATED FETCH FIRST 5 ROWS ONLY;

Mysql:

SELECT ID, UPDATED FROM JIRA.JIRAISSUE ORDER BY UPDATED DESC LIMIT 5;

Refer stackflow link

Monday, September 10, 2018

How To Move Docker Images OS Files From Default To Different OS Location

Requirement:

    By default docker ce is installed on /var/lib/docker which may have limited space. As more and more images are coming and easy for moving images, we better put images on mounted Filesystem

Solution:

   Scope: it is tested on Docker 18.06.1-ce  on Linux

  • As root
  • systemctl stop docker
  • mv /var/lib/docker   /bigdisk/apps/docker
  • ln -s /bigdisk/apps/docker  /var/lib/docker
  • systemctl start docker
It will work fine after restart


Wednesday, September 05, 2018

Proxy Settings For Docker Daemon and Docker Containers

Proxy Settings For Docker Daemon

 Scope: Oracle Linux 7  +  Docker 18.06.0-ce
  • refer docker doc link
  • Create a systemd drop-in directory for the docker service
  • mkdir -p /etc/systemd/system/docker.service.d
  • Create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
  • systemctl daemon-reload
  • systemctl  restart docker
  • Docker daemon can access internet via proxy

Proxy Settings For Docker Containers

 Scope: Oracle Linux 7  +  Docker 18.06.0-ce
  • refer docker doc link
  • create or edit the file ~/.docker/config.json
  • In our case, we run docker as root, it is /root/.docker/config.json
add below into the file
{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://127.0.0.1:3001",
     "noProxy": "*.test.example.com,.example2.com"
   }
 }
}
  • save the file. 
  • Next time when we start a new container, it will add this proxy automatically

Monday, September 03, 2018

Python3 File Open() and Print() Tips

Sample File Content

$ cat xmen_base.txt
Storm
Wolverine
test

#type and boolean attr of  file

>>> xmen_file = open('xmen_base.txt','r')
>>> xmen_file
<_io.TextIOWrapper name='xmen_base.txt' mode='r' encoding='cp1252'>
>>> type(xmen_file)
<class '_io.TextIOWrapper'>
>>> bool(xmen_file)
True

#print() add a newline at each end

>>> for a in xmen_file:
...     print(a)
...
Storm

Wolverine

test

>>> xmen_file.seek(0)
0

#tell print() not to add newline at each end

>>> for a in xmen_file:
...     print(a,end='')
...
Storm
Wolverine
test

#tell print() to add ; at end of each end

>>> xmen_file.seek(0)
0
>>> for a in xmen_file:
...     print(a.strip() + ';')
...
Storm;
Wolverine;
test;
>>> xmen_file.close()

Python open file mode detailed explaination .Quote from link

The argument mode points to a string beginning with one of the following
 sequences (Additional characters may follow these sequences.):

 ``r''   Open text file for reading.  The stream is positioned at the
         beginning of the file.

 ``r+''  Open for reading and writing.  The stream is positioned at the
         beginning of the file.

 ``w''   Truncate file to zero length or create text file for writing.
         The stream is positioned at the beginning of the file.

 ``w+''  Open for reading and writing.  The file is created if it does not
         exist, otherwise it is truncated.  The stream is positioned at
         the beginning of the file.

 ``a''   Open for writing.  The file is created if it does not exist.  The
         stream is positioned at the end of the file.  Subsequent writes
         to the file will always end up at the then current end of file,
         irrespective of any intervening fseek(3) or similar.

 ``a+''  Open for reading and writing.  The file is created if it does not
         exist.  The stream is positioned at the end of the file.  Subse-
         quent writes to the file will always end up at the then current
         end of file, irrespective of any intervening fseek(3) or similar.

Saturday, September 01, 2018

Some Python Logic Operations Tips

Python or and logic Operations Meaning: 

Boolean on functions

All print( ) boolean is false is because print() does not return anything. it returns None. If a function returns a none-zero value, boolean is True

>>> bool(print('aa'))
aa
False
>>> bool(print(''))

False

>>> def add_two(num):
...    return num + 2
...
>>> add_two(3)
5
>>> '' or "" or None or add_two(4) or print('gg')
6
>>> '' or "" or None or add_two(-2) or print('gg')
gg

OR

It  find&return first true or return last expression
examples:
>>> 100 or 33 or 55
100
>>> 100 or 0 or 55

100
>>> '' or "" or None or print('ddd') or print('gg')
ddd
gg
>>> '' or "" or None or print('ddd') or 'aa' or print('gg')
ddd
'aa'
>>> '' or "" or None or print('ddd')
ddd

AND

It find&return first false or return last expression
examples:

>>> 100 and 33 and 55
55
>>> 100 and 0 and 55

0
>>> print('aaa') and print('bbb') and ''

aaa
>>> '' and  "" and None and  print('ddd')
''
>>> 'aa' and '' and print('dddd')
''