顯示具有 Linux 標籤的文章。 顯示所有文章
顯示具有 Linux 標籤的文章。 顯示所有文章

星期一, 5月 06, 2019

disable firewall and selinux in CentOS 7

Linux init configuration for test MQ

1. disable selinux
vi /etc/selinux/config
SELINUX=disabled

=> reboot

2. disable firewall
systemctl stop firewalld.service (one time)
systemctl disable firewalld.service (all time)



https://www.opencli.com/linux/centos-7-disable-firewalld-selinux

星期三, 4月 03, 2019

How to reformat MQ error message

The content of the MQ error log is as following:

12/08/2018 08:21:42 AM - Process(16535.4) User(root) Program(amqzmur0)
                    Host(love) Installation(Installation1)
                    VRMF(8.0.0.9) QMgr(QM2)
                 
AMQ6287: WebSphere MQ V8.0.0.9 (p800-009-180321.1).

EXPLANATION:
WebSphere MQ system information:
Host Info         :- Linux 2.6.32-696.13.2.el6.x86_64 (MQ Linux (x86-64
platform) 64-bit)
Installation      :- /opt/mqm (Installation1)
Version           :- 8.0.0.9 (p800-009-180321.1)
ACTION:
None.
-------------------------------------------------------------------------------
12/08/2018 08:21:41 AM - Process(30069.1) User(root) Program(runmqchl)
                    Host(love) Installation(Installation1)
                    VRMF(8.0.0.9) QMgr(QM2)
                 
AMQ9213: A communications error for TCP/IP occurred.

EXPLANATION:
An unexpected error occurred in communications.
ACTION:
The return code from the TCP/IP (connect) call was 113 (X'71'). Record these
values and tell the systems administrator.
----- amqccita.c : 1278 -------------------------------------------------------
12/08/2018 08:21:41 AM - Process(30069.1) User(root) Program(runmqchl)
                    Host(love) Installation(Installation1)
                    VRMF(8.0.0.9) QMgr(QM2)
                 
AMQ9999: Channel 'QM2.V9QM2' to host '192.168.136.123(1415)' ended abnormally.

EXPLANATION:
The channel program running under process ID 30069 for channel 'QM2.V9QM2'
ended abnormally. The host name is '192.168.136.123(1415)'; in some cases the
host name cannot be determined and so is shown as '????'.
ACTION:
Look at previous error messages for the channel program in the error logs to
determine the cause of the failure. Note that this message can be excluded
AMQERR01.LOG


However I would like to reformat the error log as following:

12/08/2018 08:21:42 AM AMQ6287: WebSphere MQ V8.0.0.9 (p800-009-180321.1).
12/08/2018 08:21:41 AM AMQ9213: A communications error for TCP/IP occurred.
12/08/2018 08:21:41 AM AMQ9999: Channel 'QM2.V9QM2' to host '192.168.136.123(1415)' ended abnormally.

Only grep is not enough to handle, we must ask help from 'sed"

grep -o -E ".*[0-9]{2}:[0-9]{2}:[0-9]{2}\ [A,P]{,1}[M]{,1}[:space:]{,1}|AMQ[0-9]{4}:.*" AMQERR01.LOG|sed '$!N;s/\n/\ /'

grep:
-o: only print the match string
*** AIX 上的opensoure grep 要用[[:space:]]

sed:
N means read the next line (可用來合併二行)
$!N means read the next line unless it is the last line (最後一行不做)

sed   N和$!N 的理解使用


星期四, 1月 03, 2019

Find out which process is using a port in Linux

1. netstat
# netstat -tuplna|grep port_number
[root@love ~]# netstat -tuplan|grep 1477
tcp        0      0 :::1477                     :::*                        LISTEN      12129/runmqlsr
tcp        0      0 ::ffff:127.0.0.1:1477       ::ffff:127.0.0.1:50240      ESTABLISHED 12710/amqrmppa
tcp        0      0 ::ffff:127.0.0.1:50240      ::ffff:127.0.0.1:1477       ESTABLISHED 23447/java

從上面結果可知:
(1)pid 12129 (runmqlsr)    這個process 在LISTEN 1477這個port
(2)pid 12710 (amqrmppa) 這個process用127.0.0.1的1477 port連往 127.0.0.1的50240 port
(3)pid 23447 (java)           這個process 用127.0.0.1的50240 port連往 127.0.0.1的1477 port


2. fuser
#fuser port_number/tcp -u -v
[root@love ~]# fuser 1477/tcp -u -v
                     USER        PID   ACCESS    COMMAND
1477/tcp:      mqm       12129   F....            (mqm)runmqlsr
                     mqm       12710   F....            (mqm)amqrmppa

3. lsof
#lsof -i :port_number
[root@love ~]# lsof -i :1477
COMMAND  PID  USER FD TYPE DEVICE SIZE/OFF NODE NAME
runmqlsr        12129  mqm   5u  IPv6      699704    0t0       TCP *:ms-sna-server (LISTEN)
amqrmppa     12710  mqm   6u  IPv6     2028669   0t0       TCP localhost:ms-sna-server->localhost:50240 (ESTABLISHED)
java               23447   root  118u  IPv6    2028668   0t0       TCP localhost:50240->localhost:ms-sna-server (ESTABLISHED)

Ref:
Linux Find Out Which Process Is Listening Upon a Port
https://www.cyberciti.biz/faq/what-process-has-open-linux-port/

星期五, 4月 27, 2018

alias 無法使用多個指令串接解決方法

因為練習Docker, 想要把以下指令串寫成一個alias 命令來一次刪除所有的container
docker ps -a|awk '{print $1}'|grep -v CONTAINER|xargs -n 1 docker rm
但發現bash會認為語法不對, 在stackoverflow 發現以下解法, 將其寫成function (.bashrc)

docrmall() {
docker ps -a|awk '{print $1}'|grep -v CONTAINER|xargs -n 1 docker rm
}

以後只要呼叫 docrmall就可以了!

Syntax error when trying to pipe multiple commands in an alias definition

***
xargs -n 1 : 代表一次用一個值傳給後面的命令當輸入值

Linux 系統 xargs 指令範例與教學


*** update: 發現另外方式更快, 主要是 -q 這個選項可以只輸出id, 不需再去grep

(1) docker rm -f  $(docker ps -aq)
或是
(2) docker ps -aq|xargs docker rm

***

$(    )   --->  取得( ) 內的指令輸出內容

星期三, 5月 03, 2017

How to pass password to su

su command only accept password from terminal in normal case. The following is using "expect" command to overcome this restriction. However this is not secure.

You must install expect package before using this command.

http://blog.roodo.com/ystuan/archives/6128305.html
https://blog.longwin.com.tw/2011/07/expect-shell-auto-linux-2011/

We can use autoexpect tool to help us to build the script.

#!/usr/bin/expect -f
set timeout -1
spawn su -c {cp /tmp/a.txt /tmp/b.txt}
match_max 100000
expect -exact "Password: "
send -- "your_root_password\r"
expect eof


However this is not secure, it will leave your root_password in this file.
We should use sudo -S to do this job.

http://blog.roodo.com/ystuan/archives/6128305.html
https://blog.longwin.com.tw/2011/07/expect-shell-auto-linux-2011/



星期三, 4月 12, 2017

How to find out all used ports for the specified process in Linux and AIX


1. For Linux:
    It's easy to use the following command:
    #netstat -tupln|grep pid_of_your_process

2. For AIX:
    You must combine several commands:
    #netstat -Aan|grep LISTEN|awk '{print $1}'|xargs -i rmsock {} tcpcb > a.txt
    #netstat -Aan|grep LISTEN|awk '{print $5"\t\t"}' > b.txt
    #paste b.txt a.txt > c.txt
    #grep pid_of_your_process c.txt

*** xargs -i can use the output of previous command to replace the {} as the argument of the next command.


星期五, 2月 17, 2017

How to install software or upgrade from an old unsupported release?

How to install software or upgrade from an old unsupported release?



sudo sed -i -re 's/([a-z]{2}\.)?archive.ubuntu.com|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list

Why are we facing 404 errors

Ubuntu follows the approach of two different release cycles:
Normal Ubuntu releases are supported for 9 months. LTS releases are supported for 5 years.
Past releases may have different support schedules (for example, normal releases (before 13.04) used to be supported for 18 months, while LTS releases (before 12.04) used to be supported for 3 years on the desktop and 5 years on the server).
EOL: Once the support period for a particular release is over; they are called End Of Life (EOL) and all the updates and package repositories for that Release are transferred to a different server which results in 404 errors while running sudo apt-get update. You can confirm if your release has become EOL by going to this page. If your Ubuntu release is mentioned under "End Of Life (EOL)" Table, then the release is no longer supported and you should try to upgrade to a newer supported release. However, if you wish to continue using this unsupported release, you would have to make necessary modifications in /etc/apt/sources.list to point to the old-releases server of Ubuntu.
There you go. No 404 Errors this time. You can now install all the available packages for your Ubuntu Release. You can also run sudo apt-get dist-upgrade to install any Security/Bug-fix updates which have not yet been installed but you won't get any further Security/Bug-fix updates from Ubuntu.