2023年3月26日 星期日

Ansbile vi 設定

 

echo -e 'autocmd FileType yaml setlocal ai ts=2 sw=2 et\n:set cursorcolumn' > ~/.vimrc



2020年7月5日 星期日

Oracle 19C



OPATCH

https://updates.oracle.com/download/6880880.html

PSU

https://support.oracle.com/epmos/faces/PatchResultsNDetails?_adf.ctrl-state=thhygvdrz_559&releaseId=600000000101150&requestId=23499641&patchId=30783543&languageId=0&platformId=226&searchdata=%3Ccontext+type%3D%22BASIC%22+search%3D%22%26lt%3BSearch%26gt%3B%26lt%3BFilter+name%3D%26quot%3Bpatch_number%26quot%3B+op%3D%26quot%3Bis%26quot%3B+value%3D%26quot%3B30783543%26quot%3B%2F%26gt%3B%26lt%3B%2FSearch%26gt%3B%22%2F%3E&_afrLoop=33140459169779


2020年2月2日 星期日

oracle tnsnames.ora


http://www.aspphp.online/shujuku/oraclesjk/oraclezs/201701/226892.html

環境
db01  = 192.168.240.171  ver 11.2.0.4
db03 =  192.168.240.173  ver 19.3.0.0



--- Create User

CREATE USER  pythonhol  IDENTIFIED BY welcome   ;
-- SYSTEM PRIVILEGES
GRANT CREATE SESSION TO  pythonhol   ;
GRANT SELECT ANY DICTIONARY TO pythonhol    ;














---

Test Client


db1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.240.171)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

db3 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.240.173)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

db =
  (DESCRIPTION =
    (LOAD_BALANCE=on)
    (FAILOVER=on)
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.240.171)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.240.173)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )




t.py

#!python

import cx_Oracle
con = cx_Oracle.connect('pythonhol/welcome@db')
cur = con.cursor()
cur.execute('SELECT  host_name FROM    v$instance')
for result in cur:
    print result
cur.close()
con.close()   


手工配置tnsnames.ora的空格问题




本文给出一个手工配置tnsnames.ora极易出错的一个案例:谨慎处理空格!

1.标准的tnsnames.ora内容
ora10g@secdb /home/oracle$ vi $ORACLE_HOME/network/admin/tnsnames.ora
……
ORA10G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = secdb)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ora10g)
    )
  )
……

标准的配置以精美的缩进展示了连接串的配置,很容易阅读。
建议以此为模板去配置其他的连接串。

2.其他形式的配置
1)无缩进形式
ORA10G =
(DESCRIPTION =
 (ADDRESS = (PROTOCOL = TCP)(HOST = secdb)(PORT = 1521))
 (CONNECT_DATA =
 (SERVER = DEDICATED)
 (SERVICE_NAME = ora10g)
 )
)

上面这种书写形式没有缩进,因此可阅读性就大大地降低了。不过这种形式是可行的。
这里需要提醒的是:连接串名需要顶头书写,数据库连接串定义中除首尾括号外不允许其他内容顶头书写!(后面会有错误例子)

2)一行搞定一切
ORA10G=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=secdb)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ora10g)))



这是最精简的一种配置,但是缺点非常显然:很难快速的理清语法关系。这种配置方法可集成在脚本中,达到快速编辑测试环境下的tnsnames.ora配置文件的目的。


ORA10G =
(DESCRIPTION =
 (ADDRESS = (PROTOCOL = TCP)(HOST = secdb)(PORT = 1521))
 (CONNECT_DATA =
(SERVER = DEDICATED)
 (SERVICE_NAME = ora10g)
 )
)

紅色部份需縮排,無縮排即無法使用


————————————————
版权声明:本文为CSDN博主「半支烟丶」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/q82272513/article/details/50856493


2020年1月22日 星期三

2019年12月20日 星期五

apache-fake-log-gen.py


# pip install
curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py

pip install pytz
pip install numpy
pip install faker
pip install tzlocal

# apache-fake-log-gen.py
get https://raw.githubusercontent.com/kiritbasu/Fake-Apache-Log-Generator/master/apache-fake-log-gen.py

來源:
https://github.com/kiritbasu/Fake-Apache-Log-Generator/blob/master/apache-fake-log-gen.py





#CODE:
#!/usr/bin/python
import time
import datetime
import pytz
import numpy
import random
import gzip
import zipfile
import sys
import argparse
from faker import Faker
from random import randrange
from tzlocal import get_localzone
local = get_localzone()

#todo:
# allow writing different patterns (Common Log, Apache Error log etc)
# log rotation


class switch(object):
    def __init__(self, value):
        self.value = value
        self.fall = False

    def __iter__(self):
        """Return the match method once, then stop"""
        yield self.match
        raise StopIteration

    def match(self, *args):
        """Indicate whether or not to enter a case suite"""
        if self.fall or not args:
            return True
        elif self.value in args: # changed for v1.5, see below
            self.fall = True
            return True
        else:
            return False

parser = argparse.ArgumentParser(__file__, description="Fake Apache Log Generator")
parser.add_argument("--output", "-o", dest='output_type', help="Write to a Log file, a gzip file or to STDOUT", choices=['LOG','GZ','CONSOLE'] )
parser.add_argument("--log-format", "-l", dest='log_format', help="Log format, Common or Extended Log Format ", choices=['CLF','ELF'], default="ELF" )
parser.add_argument("--num", "-n", dest='num_lines', help="Number of lines to generate (0 for infinite)", type=int, default=1)
parser.add_argument("--prefix", "-p", dest='file_prefix', help="Prefix the output file name", type=str)
parser.add_argument("--sleep", "-s", help="Sleep this long between lines (in seconds)", default=0.0, type=float)

args = parser.parse_args()

log_lines = args.num_lines
file_prefix = args.file_prefix
output_type = args.output_type
log_format = args.log_format

faker = Faker()

timestr = time.strftime("%Y%m%d-%H%M%S")
otime = datetime.datetime.now()

outFileName = 'access_log_'+timestr+'.log' if not file_prefix else file_prefix+'_access_log_'+timestr+'.log'

for case in switch(output_type):
    if case('LOG'):
        f = open(outFileName,'w')
        break
    if case('GZ'):
        f = gzip.open(outFileName+'.gz','w')
        break
    if case('CONSOLE'): pass
    if case():
        f = sys.stdout

response=["200","404","500","301"]

verb=["GET","POST","DELETE","PUT"]

resources=["/list","/wp-content","/wp-admin","/explore","/search/tag/list","/app/main/posts","/posts/posts/explore","/apps/cart.jsp?appID="]

ualist = [faker.firefox, faker.chrome, faker.safari, faker.internet_explorer, faker.opera]

flag = True
while (flag):
    if args.sleep:
        increment = datetime.timedelta(seconds=args.sleep)
    else:
        increment = datetime.timedelta(seconds=random.randint(30, 300))
    otime += increment

    ip = faker.ipv4()
    dt = otime.strftime('%d/%b/%Y:%H:%M:%S')
    tz = datetime.datetime.now(local).strftime('%z')
    vrb = numpy.random.choice(verb,p=[0.6,0.1,0.1,0.2])

    uri = random.choice(resources)
    if uri.find("apps")>0:
        uri += str(random.randint(1000,10000))

    resp = numpy.random.choice(response,p=[0.9,0.04,0.02,0.04])
    byt = int(random.gauss(5000,50))
    referer = faker.uri()
    useragent = numpy.random.choice(ualist,p=[0.5,0.3,0.1,0.05,0.05] )()
    if log_format == "CLF":
        f.write('%s - - [%s %s] "%s %s HTTP/1.0" %s %s\n' % (ip,dt,tz,vrb,uri,resp,byt))
    elif log_format == "ELF":
        f.write('%s - - [%s %s] "%s %s HTTP/1.0" %s %s "%s" "%s"\n' % (ip,dt,tz,vrb,uri,resp,byt,referer,useragent))
    f.flush()

    log_lines = log_lines - 1
    flag = False if log_lines == 0 else True
    if args.sleep:
        time.sleep(args.sleep)

2019年11月8日 星期五

34_tail hilght



34_tail hilght

高亮 tail 指令

tail -f xxx.log | perl -pe 's/(ERROR)/\e[1;31m$1\e[0m/g'


H1(){
if [ "$#" -ne 2 ]
then
echo "\$1 關鍵字"
echo "\$2 色碼"
echo "色碼"
return
fi
perl -pe 's/('$1')/\e[1;'$2'm$1\e[0m/g';
}

底線:  4
反白:  7



cat /etc/passwd |  perl -pe 's/(retired gracefully)/\e[1;41m$1\e[0m/g' |\
  perl -pe 's/(deployment)/\e[1;42m$1\e[0m/g'


H1(){ perl -pe 's/('$1')/\e[1;'$2'm$1\e[0m/g'; }
for i in {1..50}
do
echo $i
echo ABCD| H1 BC $i
done

RHEL install EPEL

  https://www.linuxtechi.com/install-epel-repo-on-rhel-system/ EPEL dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest...