Posts

How to print only the previous 5th and 6th lines using the 'grep' command

How to print only the previous 5th and 6th lines using the 'grep' command grep total -B 5 -w my.test | awk '( ((NR%7) == 1) || ((NR%7) == 6 )) { print $0 } ' | more

[WordPress] Change https redirect in DB.

If you make an https redirect without thinking about SSL configuration: Check DB SELECT * from wp_options where option_name IN ('siteurl', 'home'); Update UPDATE wp_options SET option_value = REPLACE(option_value, 'https://your_domain', 'http://your_domain') WHERE option_name IN ('siteurl', 'home');

Setup pyodbc for connecting mssql (with freeTDS)

@Windows 1. pip install pyodbc 2.  Install Windows ODBC driver:  https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-2016 @Linux (Ubuntu-base) 1. freeTDS install using apt apt-get install freetds-dev freetds-bin apt-get install tdsodbc Explanation tdsodbc => /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so freetds-dev freetds-bin => /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so and etc files 2.  edit or add in /etc/odbcinst.ini [FreeTDS] Description = FreeTDS ODBC Driver Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so FileUsage = 1 CPTimeout = CPReuse = Example code: import pyodbc connection_string = ( 'DRIVER={FreeTDS};' 'SERVER=1.2.3.4;' 'PORT=1433;' 'DATABASE=mydbname;' 'UID=myuser;' 'PWD=password;' 'TDS_Version=7.3;' # 'Encrypt=no;TrustServerCertificate=yes;Trusted_Connection=no;' ) ...

[Linux/k8s] set faking hyper-v uuid on k8s woker node

* conclusion     Unable to create weave-net (pod-to-pod connection) which works well with conflicting uuid. So in the end i reinstalled ubuntu in hyper-v (not import mode). remap-uuid.sh #!/bin/bash function make_bind_or_copy() {   if [ "$3" == "bind" ]; then     echo "MountBind $1 > $2"     mount -o ro,bind "$1" "$2"   else # copy     echo "Copy $1 > $2"     cp "$1" "$2"   fi } function make_newID() {   TITLE="$1"   ORG_FILE="$2"   TAR_FILE="$3"   BIND_MODE="$4"   if -f [ -f $TAR_FILE ]; then     make_bind_or_copy "${TAR_FILE}" "${ORG_FILE}" "${BIND_MODE}"     return   fi   CUR_ID=`cat ${ORG_FILE}`   echo "Current   ${TITLE}: ${CUR_ID}"   echo -n "Write New ${TITLE}: "   read NEW_ID   echo "Inputed   ${TITLE}: ${NEW_ID}"   echo "${NEW_ID}" > ${TAR_FILE}   echo -n "Re-Write(mount) ${OR...

Linux/Process fork monitoring

ps_moniter.sh  #!/bin/bash . /etc/profile let LIMIT_PROCESS=400 let LIMIT_BIG_PROCESS=40 ALL_PROCESS_NUM=`ps x |wc -l` if [ ${ALL_PROCESS_NUM} -gt ${LIMIT_PROCESS} ]; then   echo ${ALL_PROCESS_NUM} fi BIG_PROCESS=`ps x -o cmd |sort  |uniq -c |sort -n |tail -n 10` BIG_PROC_SUM=`echo "${BIG_PROCESS}" |awk ' { SUM=SUM+$1 } END { print SUM } '` if [ ${BIG_PROC_SUM} -gt ${LIMIT_BIG_PROCESS} ]; then   MESSAGE="Process Report [Big Process Larger than ${LIMIT_BIG_PROCESS}] ${BIG_PROCESS}"   echo "$MESSAGE" fi crontab */5 * * * * cd /root/bin && ./ps_moniter.sh &>/dev/null

uri modificatin on http response

In haproxy : cannot. In nginx : possible. Backend Host: 1.2.3.4 Frontend Host: 2.2.2.2         location ^~ /its/         {             proxy_buffering   off;             rewrite           /its/(.*) /$1 break;             proxy_pass        http://1.2.3.4/;             proxy_redirect    default;             sub_filter_once off;             sub_filter ' href="/' ' href="/its/';             sub_filter ' src="/' ' src="/its/';             sub_filter ' src="http://1.2.3.4/' ' src="/its/';             sub_filter ' action="/' ' action="/its/';         } ex1. 2.2.2.2/its --> (2.2.2.2 connect to 1.2.3...

rsyslog file log to remote syslog

 1. rsyslog    [file-A]     <--->    [remote rsyslog] 1) Edit conf file (The filename is your choice.)   @: udp   @@: tcp /etc/rsyslog.d/01-testlog.conf $ModLoad imfile # Default Apache Access Log $InputFileName /var/log/haproxy.log #$InputFileName /var/log/httpd/access_log #$InputFileTag httpd-access-default: #$InputFileStateFile stat-httpd-access #$InputFileSeverity info $InputFileFacility local4 $InputRunFileMonitor $InputFilePollInterval 10 local4.* @127.0.0.1:514 2) ignore local4 from /var/log/message and /var/log/syslog   edit /etc/rsyslog.conf Before: *.*;auth,authpriv.none    -/var/log/syslog After: *.*;!(local4.*);auth,authpriv.none    -/var/log/syslog Before: *.=debug;\   auth,authpriv.none;\   news.none;mail.none -/var/log/debug *.=info;*.=notice;*.=warn;\   auth,authpriv.none;\   cron,daemon.none;\   mail,news.none    -/var/log/messages  After: *...