poniedziałek, 21 listopada 2016

delete elastic search index

[root@srv indices]# curl -XDELETE 'admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.1{2,3,4,5}'

[1/4]: admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.12 --> <stdout>
--_curl_--admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.12
{"acknowledged":true}
[2/4]: admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.13 --> <stdout>
--_curl_--admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.13
{"acknowledged":true}
[3/4]: admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.14 --> <stdout>
--_curl_--admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.14
{"acknowledged":true}
[4/4]: admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.15 --> <stdout>
--_curl_--admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.15

{"acknowledged":true}[root@srv indices]# curl -XDELETE 'admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.1{6,7,8,9}'

[1/4]: admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.16 --> <stdout>
--_curl_--admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.16
{"acknowledged":true}
[2/4]: admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.17 --> <stdout>
--_curl_--admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.17
{"acknowledged":true}
[3/4]: admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.18 --> <stdout>
--_curl_--admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.18
{"acknowledged":true}
[4/4]: admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.19 --> <stdout>
--_curl_--admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.11.19

wtorek, 1 listopada 2016

Python String Formating - get first char and make it capitalize

#!/usr/bin/env python

def main():
   
    name = raw_input("What is your name: ")
    lastname = raw_input("What is yout lastname: ")

    age = input("Enter your age: ")
    z = "%s %s" % (name,lastname)
    x = "%s %s" % (name[:1].upper(),lastname[:1].upper())
    print z
    print x
    print("hello {} {} you have {}".format(name,lastname,age))
    mystr=name
    mstr=lastname

    print mystr[:1].upper(),mstr[:1].upper()
    string = "marek borkowski"
    print string[0].upper()+string[1:]



if __name__ == "__main__":
    main()

niedziela, 30 października 2016

hacker range bash - case about tr switch signs

marek@ubuntu:~/dev/bash$ echo "int i=(int)5.8 (23 + 5)*2" | tr '()' '[]'
int i=[int]5.8 [23 + 5]*2
marek@ubuntu:~/dev/bash$ echo "int i=(int)5.8 (23 + 5)*2" | tr "(" "[" | tr ")" "]"

selective file remove

shopt -s extglob
root@ubuntu:~/dev/python/tmp# for i in  1 2 3 4 5; do touch $i; done
root@ubuntu:~/dev/python/tmp# ll
razem 0
-rw-r--r-- 1 root root 0 paź 30 14:37 3
-rw-r--r-- 1 root root 0 paź 30 14:37 2
-rw-r--r-- 1 root root 0 paź 30 14:37 1
-rw-r--r-- 1 root root 0 paź 30 14:37 5
-rw-r--r-- 1 root root 0 paź 30 14:37 4

root@ubuntu:~/dev/python/tmp# rm -v !("3")
usunięty '1'
usunięty '2'
usunięty '4'
usunięty '5'

root@ubuntu:~/dev/python/tmp# ls -ltr
razem 0

piątek, 28 października 2016

Sum Dir Size awk

[root@dimlogsrvvmd1 indices]# du -sk * | sort -nr | grep prod-crm | awk '{total = total + $1}END{print "CRM log sum = "total/1024/1024 " gb"}'

CRM log sum = 97.6993 gb

czwartek, 27 października 2016

check app deployment on docker wildfly

#!/bin/bash

for i in `docker ps -q`; do
        for j in `cat lista.dat| grep curl | grep -v \# |  awk '{print $NF}' | awk -F"/" '{print $2}'`; do
                echo $i && docker exec -it $i /opt/wildfly9/bin/jboss-cli.sh --connect "deployment-info --name=$j"
        done
done

1. first loop get docker container id
2. second loop are get list of deployed artifact's

example of loop in loop - nested loop


#!/bin/bash


outer=1             # Set outer loop counter.

# Beginning of outer loop.
for a in 1 2 3 4 5
do
  echo "Pass $outer in outer loop."
  echo "---------------------"
  inner=1           # Reset inner loop counter.

  # ===============================================
  # Beginning of inner loop.
  for b in 1 2 3 4 5
  do
    echo "Pass $inner in inner loop."
    let "inner+=1"  # Increment inner loop counter.
  done
  # End of inner loop.
  # ===============================================

  let "outer+=1"    # Increment outer loop counter. 
  echo              # Space between output blocks in pass of outer loop.
done               
# End of outer loop.

exit 0

Other way to print few first and last line of file

[marek.borkowski@wildvmi2.polsatc ~]$ cat line_test | awk 'NR > 3 { exit }; 1'
1 line
2 line
3 line

[marek.borkowski@wildvmi2.polsatc ~]$ cat line_test | awk 'END { print }'
5 line

sobota, 22 października 2016

sed - switch char in file and make backup file


marek@ubuntu:~/dev/bash$ sed -i.bak 's/;/:/' test.dat
marek@ubuntu:~/dev/bash$ ls -ltr
razem 16
-rwxr-xr-x 1 marek marek 108 paź 22 14:48 read.sh
-rw-r--r-- 1 marek marek 380 paź 22 14:50 food_list.txt
-rw-rw-r-- 1 marek marek  55 paź 22 15:01 test.dat.bak
-rw-rw-r-- 1 marek marek  55 paź 22 15:01 test.dat
marek@ubuntu:~/dev/bash$ cat test.dat.bak
marek;borkowski;admin;1983
wiktor;borkowski;user;2015

marek@ubuntu:~/dev/bash$ cat test.dat
marek:borkowski;admin;1983
wiktor:borkowski;user;2015

piątek, 14 października 2016

fuser - lsof substitute - another swiss army knife

[root@dimlogsrvvmd1 logstash]# fuser -n tcp -v 80
                     USER        PID ACCESS COMMAND
80/tcp:              root       1970 F.... httpd
                     apache     6015 F.... httpd
                     apache     6016 F.... httpd
                     apache     6019 F.... httpd
                     apache     6024 F.... httpd
                     apache    25308 F.... httpd
                     apache    61429 F.... httpd
                     apache    61430 F.... httpd
                     apache    61431 F.... httpd
                     apache    61432 F.... httpd
                     apache    61433 F.... httpd

środa, 12 października 2016

Check Top Processes sorted by RAM or CPU Usage in Linux

root@ubuntu:~# ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

  PID  PPID CMD                         %MEM %CPU
 1254     1 /usr/lib/jvm/java-8-openjdk  1.7  0.8
 1096     1 /usr/bin/docker daemon -H f  0.4  0.1
 1355  1096 containerd -l /var/run/dock  0.1  0.0
  954     1 /usr/lib/snapd/snapd         0.1  0.0
 1353  1098 sshd: marek [priv]           0.0  0.0
 1645  1098 sshd: marek [priv]           0.0  0.0
  914     1 /usr/lib/accountsservice/ac  0.0  0.0
 1285  1282 /usr/sbin/apache2 -k start   0.0  0.0
 1286  1282 /usr/sbin/apache2 -k start   0.0  0.0

poniedziałek, 10 października 2016

sobota, 8 października 2016

bash command statistic

root@ubuntu:~# fc -l
16       tail -f zorka.log
17       ll
18       ssh marek@ny1.hashbang.sh
19       echo 'obase=17;1234' | bc
20       echo 'obase=8;1234' | bc
21       echo 'obase=2;1234' | bc
22       echo 'obase=10;1234' | bc
23       root@ubuntu:~# echo 'obase=17;1234' | bc
24       root@ubuntu:~# echo 'obase=8;1234' | bc
25       2322
26       root@ubuntu:~# echo 'obase=2;1234' | bc
27       10011010010
28       root@ubuntu:~# echo 'obase=10;1234' | bc
29       1234
30       col() { awk '{print $'$(echo $* | sed -e 's/ /,$/g')'}'; }
31       fcc -l

bash math converter

root@ubuntu:~# echo 'obase=17;1234' | bc
 04 04 10

root@ubuntu:~# echo 'obase=8;1234' | bc
2322

root@ubuntu:~# echo 'obase=2;1234' | bc
10011010010

root@ubuntu:~# echo 'obase=10;1234' | bc
1234

piątek, 7 października 2016

find swaping process

[root@app01.prod.crm.polsatc marek.borkowski]# for i in `ps -ef | grep java |grep -v grep| awk '{print $2}'`;do echo $i && cat /proc/$i/status | grep VmSwap && echo "------"; done
60582
VmSwap:   184464 kB
------
60912
VmSwap:    83324 kB
------
61242
VmSwap:     9840 kB

wtorek, 4 października 2016

get file from server with telnet

 $ (echo 'GET /'; echo; sleep 1; ) | telnet www.google.com 80

Find recent logs that contain the string "Exception"

find . -name '*.log' -mtime -2 -exec grep -Hc Exception {} \; | grep -v :0$

run simple http server - nc swiss knife ;)

while true; do echo "tcp server is running ...." && nc -l -p 8081 < hashbang.sh; done

binary clock :)

root@ubuntu:~# perl -e 'for(;;sleep 1){printf"\r"."%.4b "x6,split"",`date +%H%M%S`}'
0010 0010 0011 1001 0101 0110

nice port scanner

root@ubuntu:~# netcat -z -n -v 127.0.0.1 8000-10000 2>&1 | grep succeeded
Connection to 127.0.0.1 8005 port [tcp/*] succeeded!
Connection to 127.0.0.1 8080 port [tcp/*] succeeded!

share file from terminal

root@ubuntu:~# curl --upload-file hashbang.sh https://transfer.sh/bang.sh

https://transfer.sh/14HMjM/bang.sh

Thread count per user

ps -u jboss -o nlwp= | awk '{ num_threads += $1 } END { print num_threads }'

get the external ip address

root@ubuntu:~# curl -s httpbin.org/ip | jq -r .origin
31.179.165.22

run command in sequence

for i in {1..10}; do time curl http://localhost:8000 >/dev/null; done 2>&1 | grep real
root@ubuntu:~# for i in {1..10}; do time curl http://localhost:8000 >/dev/null; done 2>&1 | grep real
real    0m0.011s
real    0m0.006s
real    0m0.005s
real    0m0.006s
real    0m0.006s
real    0m0.005s
real    0m0.009s
real    0m0.011s
real    0m0.005s
real    0m0.005s

print load average

python -c 'import os;print os.getloadavg()[0]'

10 largest open files

lsof / | awk '{ if($7 > 1048576) print $7/1048576 "MB" " " $9 " " $1 }' | sort -n -u | tail

Display connected host to out server based on port.

clear;while x=0; do clear;date;echo "";echo "  [Count] | [IP ADDR]";echo "-------------------";netstat -np|grep :80|grep -v LISTEN|awk '{print $5}'|cut -d: -f1|uniq -c; sleep 5;done

poniedziałek, 3 października 2016

piątek, 30 września 2016

docker update

update memory settings
docker update --memory=6G --memory-swap=10G crm-prd-n3-3

[root@app03.prod.crm.polsatc ~]# docker inspect crm-prd-n3-3 | grep -i memory
            "KernelMemory": 0,
            "Memory": 6442450944,
            "MemoryReservation": 0,
            "MemorySwap": 10737418240,
            "MemorySwappiness": -1,

Regular Exp Match line not containing string

CP-DEV-CRM-Procesy-((?!Common).)*$

print line not contain Common

http://www.regextester.com/15

regexp tester:

https://regex101.com/

czwartek, 29 września 2016

read hprof file

λ jhat.exe C:\Users\marek.borkowski\Documents\heapdump.hprof
Reading from C:\Users\marek.borkowski\Documents\heapdump.hprof...

Dump file created Tue Sep 27 07:28:55 CEST 2016

Chasing references, expect 361 dots.........................................................................................................................................................................................................................................................................................................................................................................
Eliminating duplicate references.........................................................................................................................................................................................................................................................................................................................................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.

wtorek, 27 września 2016

get logstash stats and delete largest indices

[root@dimlogsrvvmd1 logstash]# curl -s 'admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/_cat/indices?v'|sort | grep -i crm

yellow open   prod-crm-2016.09.26      5   1   12126087            0     19.8gb         19.8gb
yellow open   prod-crm-2016.09.27      5   1    3141279            0      6.1gb          6.1gb
yellow open   uat-crm-2016.09.23       5   1       1134            0      3.3mb          3.3mb
yellow open   uat-crm-2016.09.24       5   1       9765            0     13.5mb         13.5mb
yellow open   uat-crm-2016.09.26       5   1         71            0    635.6kb        635.6kb


curl -XDELETE 'admin:Ic1oWCIbAsgpx6Hq4QnQ@localhost:9200/prod-crm-2016.09.26'

piątek, 23 września 2016

find files consist string

[root@app04.prod.crm.polsatc n1]# grep -Ril java.lang.OutOfMemoryError .
./crm-prd-n4-1.hprof
./server.log.2016-09-23-14

ncport connect tester

marek@serenity:~$ nc -zw3 serenity 22 && echo "opened" || echo "closed"
opened
marek@serenity:~$ nc -zw3 serenity 2211 && echo "opened" || echo "closed"
closed

wtorek, 13 września 2016

http server netcut


server:

marek: ~ $ while true; do nc -l 5555 < test.txt ; done
GET / HTTP/1.1
Host: localhost:5555
User-Agent: curl/7.43.0
Accept: */*


client:

marek: ~ $ curl http://localhost:5555
marek borkowski


add entry to keystore - wildfly vault

λ vault.bat --keystore d:\keystore --keystore-password <keystore password> --alias Vault --vault-block wydruki.file.password --attribute PASS --sec-attr <atribute password> --enc-dir d:\vault --iteration 55 --salt 12345678

czwartek, 1 września 2016

Simple TCP multiport server

Script used for network testing


import threading
import time
import SocketServer

class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):

    def handle(self):
        self.data = self.request.recv(1024).strip()
        print "%s wrote: " % self.client_address[0]
        print self.data
        self.request.send(self.data.upper())

class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
    pass

if __name__ == "__main__":
        HOST = ''
        PORT_A = 8080
        PORT_B = 8180
        PORT_C = 9990
        PORT_D = 10090

server_A = ThreadedTCPServer((HOST, PORT_A), ThreadedTCPRequestHandler)
server_B = ThreadedTCPServer((HOST, PORT_B), ThreadedTCPRequestHandler)
server_C = ThreadedTCPServer((HOST, PORT_C), ThreadedTCPRequestHandler)
server_D = ThreadedTCPServer((HOST, PORT_D), ThreadedTCPRequestHandler)

server_A_thread = threading.Thread(target=server_A.serve_forever)
server_B_thread = threading.Thread(target=server_B.serve_forever)
server_C_thread = threading.Thread(target=server_C.serve_forever)
server_D_thread = threading.Thread(target=server_D.serve_forever)

server_A_thread.setDaemon(True)
server_B_thread.setDaemon(True)
server_C_thread.setDaemon(True)
server_D_thread.setDaemon(True)

server_A_thread.start()
server_B_thread.start()
server_C_thread.start()
server_D_thread.start()

while 1:
        time.sleep(1)

środa, 31 sierpnia 2016

get Docker container pid on core os

1. ci@gitvmd1:~$ sudo docker top ea105957eccf
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
80                  37288               37274               0                   Aug30               ?                   00:00:00            /bin/sh /opt/wildfly9/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0
80                  37382               37288               0                   Aug30               ?                   00:01:17            /usr/java/latest/bin/java -D[Standalone] -server -XX:+UseCompressedOops -server -XX:+UseCompressedOops -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Dorg.jboss.boot.log.file=/opt/wildfly9/standalone/log/server.log -Dlogging.configuration=file:/opt/wildfly9/standalone/configuration/logging.properties -jar /opt/wildfly9/jboss-modules.jar -mp /opt/wildfly9/modules org.jboss.as.standalone -Djboss.home.dir=/opt/wildfly9 -Djboss.server.base.dir=/opt/wildfly9/standalone -b 0.0.0.0 -bmanagement 0.0.0.0


2. ci@gitvmd1:~$ docker inspect --format "{{ .State.Pid }}" ea105957eccf

wtorek, 30 sierpnia 2016

how to enter to docker pid safely

sudo nsenter --target <11962/Pid number> --mount --uts --ipc --net --pid

&&
exit


how to find container id sys pid

docker inspect --format "{{ .State.Pid }}" <container-id>

Monitor docker network connection's

[marek.borkowski@w ~]$ ps -ef | grep 16430
marek.b+  4329 32495  0 14:19 pts/0    00:00:00 grep --color=auto 16430
80       16430 16324 16 12:22 ?        00:19:36 /usr/java/latest/bin/java -D[Standalone] -server -XX:+UseCompressedOops -server -XX:+UseCompressedOops -Xms512m -Xmx4096m -XX:MaxPermSize=512m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Dcom.arjuna.ats.arjuna.allowMultipleLastResources=true -Dorg.jboss.boot.log.file=/opt/wildfly9/standalone/log/server.log -Dlogging.configuration=file:/opt/wildfly9/standalone/configuration/logging.properties -jar /opt/wildfly9/jboss-modules.jar -mp /opt/wildfly9/modules org.jboss.as.standalone -Djboss.home.dir=/opt/wildfly9 -Djboss.server.base.dir=/opt/wildfly9/standalone -b 0.0.0.0 -bmanagement 0.0.0.0 --server-config=standalone.xml


[marek.borkowski@w ~]$ sudo nsenter --target 16430 --net netstat -tn | head
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 172.17.0.3:38444        192.168.107.40:50219    ESTABLISHED
tcp        0      0 172.17.0.3:8080         192.168.107.9:33322     ESTABLISHED
tcp        0      0 127.0.0.1:58334         127.0.0.1:8080          ESTABLISHED
tcp        0      0 172.17.0.3:43306        192.168.107.40:50482    ESTABLISHED
tcp        0      0 172.17.0.3:42164        192.168.107.40:50482    ESTABLISHED
tcp        0      0 172.17.0.3:8080         192.168.107.9:34686     ESTABLISHED
tcp        0      0 172.17.0.3:42212        192.168.107.40:50482    ESTABLISHED
tcp        0      0 172.17.0.3:8080         192.168.107.9:33450     ESTABLISHED

piątek, 26 sierpnia 2016

translate sign to human readable version of permissions

ci@gitvmd1:~$ stat -c '%n %a' *
biz 755
crm-config 755
dominik 755
elk 755
google-chrome-stable_current_amd64.deb 644
google-chrome-stable_current_i386.deb 644
hystrix-dashboard-1.4.18.war 644
INC_ruch.txt 644
jboss-logmanager-ext-1.0.0.Alpha3.jar 666


Easily Correct error in previous command Using ^ sign

ci@gitvmd1:~$ nestat -tanp | grep 8080
-bash: nestat: command not found

ci@gitvmd1:~$ ^nestat^netstat
netstat -tanp | grep 8080

tcp6       0      0 :::8080                 :::*                    LISTEN      -

poniedziałek, 22 sierpnia 2016

start docker container in background

ci@gitvmd1:~$ docker run -d wildm /bin/bash


13afcbcb3194c17579ecad0928780d703f73bc2bc958ba5a2cac072144225a24


ci@gitvmd1:~$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
13afcbcb3194        wildm               "/bin/sh -c '/opt/wil"   34 seconds ago      Up 33 seconds       8080/tcp, 9990/tcp   clever_poitras



niedziela, 21 sierpnia 2016

how to copy files from docer container

root@ubuntu:~# docker cp c9c1103ad566:/etc/nginx/ssl/demo.pem /tmp
root@ubuntu:~# docker cp c9c1103ad566:/etc/nginx/ssl/demo.key /tmp

root@ubuntu:~# ls -ltr /tmp/
razem 44
-rw-r--r-- 1 root          root          1976 sie 17 16:46 demo.pem
-rw-r--r-- 1 root          root          3268 sie 17 16:46 demo.key

piątek, 19 sierpnia 2016

get ip and mac from all running docker container

ci@gitvmd1:~$ for i in `sudo docker ps -q`; do sudo docker inspect --format='{{range .NetworkSettings.Networks}}MAC:{{.MacAddress}} IP: {{.IPAddress}}}{{end}}' $i;done

MAC:02:42:ac:11:00:02 IP: 172.17.0.2}
MAC:02:42:ac:11:00:01 IP: 172.17.0.1}



środa, 17 sierpnia 2016

read jboss stats via jboss-cli

1. docker exec -it da6875e4cb32 /opt/jboss/wildfly/bin/jboss-cli.sh --connect
2. [standalone@localhost:9990 /] /core-service=platform-mbean/type=memory/:read-resource(recursive=true,proxies=true,include-runtime=true,include-defaults=true)
{
    "outcome" => "success",
    "result" => {
        "heap-memory-usage" => {
            "init" => 67108864L,
            "used" => 101469392L,
            "committed" => 221773824L,
            "max" => 477626368L
        },
        "non-heap-memory-usage" => {
            "init" => 2555904L,
            "used" => 64368248L,
            "committed" => 73400320L,
            "max" => 1593835520L
        },
        "object-name" => "java.lang:type=Memory",
        "object-pending-finalization-count" => 0,
        "verbose" => false
    }
}
3. [standalone@localhost:9990 /] /core-service=platform-mbean/type=memory-pool/name=PS_Old_Gen/:read-resource(recursive=true,proxies=true,include-runtime=true,include-defaults=true)
{
    "outcome" => "success",
    "result" => {
        "name" => "PS_Old_Gen",
        "type" => "HEAP",
        "valid" => true,
        "memory-manager-names" => ["PS_MarkSweep"],
        "usage-threshold-supported" => true,
        "collection-usage-threshold-supported" => true,
        "usage-threshold" => 0L,
        "collection-usage-threshold" => 0L,
        "usage" => {
            "init" => 45088768L,
            "used" => 39194568L,
            "committed" => 78118912L,
            "max" => 358088704L
        },
        "peak-usage" => {
            "init" => 45088768L,
            "used" => 39194568L,
            "committed" => 78118912L,
            "max" => 358088704L
        },
        "usage-threshold-exceeded" => false,
        "usage-threshold-count" => 0L,
        "collection-usage-threshold-exceeded" => false,
        "collection-usage-threshold-count" => 0L,
        "collection-usage" => {
            "init" => 45088768L,
            "used" => 39194568L,
            "committed" => 78118912L,
            "max" => 358088704L
        },
        "object-name" => "java.lang:type=MemoryPool,name=\"PS Old Gen\""
    }
}


4. [standalone@localhost:9990 /] /core-service=platform-mbean/type=memory-pool/name=PS_Eden_Space/:read-resource(recursive=true,proxies=true,include-runtime=true,include-defaults=true)
{
    "outcome" => "success",
    "result" => {
        "name" => "PS_Eden_Space",
        "type" => "HEAP",
        "valid" => true,
        "memory-manager-names" => [
            "PS_MarkSweep",
            "PS_Scavenge"
        ],
        "usage-threshold-supported" => false,
        "collection-usage-threshold-supported" => true,
        "usage-threshold" => undefined,
        "collection-usage-threshold" => 0L,
        "usage" => {
            "init" => 16777216L,
            "used" => 63294592L,
            "committed" => 127401984L,
            "max" => 139460608L
        },
        "peak-usage" => {
            "init" => 16777216L,
            "used" => 67108864L,
            "committed" => 127401984L,
            "max" => 173539328L
        },
        "usage-threshold-exceeded" => undefined,
        "usage-threshold-count" => undefined,
        "collection-usage-threshold-exceeded" => false,
        "collection-usage-threshold-count" => 0L,
        "collection-usage" => {
            "init" => 16777216L,
            "used" => 0L,
            "committed" => 127401984L,
            "max" => 139460608L
        },
        "object-name" => "java.lang:type=MemoryPool,name=\"PS Eden Space\""
    }
}


5. [standalone@localhost:9990 /] /core-service=platform-mbean/type=memory-pool/name=PS_Perm_Gen/:read-resource(recursive=true,proxies=true,include-runtime=true,include-defaults=true
{
    "outcome" => "failed",
    "failure-description" => "WFLYPMB0010: No MemoryPoolMXBean with name PS_Perm_Gen currently exists",
    "rolled-back" => true
}

6. [standalone@localhost:9990 /] /host=master/server=server-one/core-service=platform-mbean/type=memory-pool/name=PS_Old_Gen:read-resource(include-runtime=true)
Failed to get the list of the operation properties: "WFLYCTL0030: No resource definition is registered for address [
    ("host" => "master"),
    ("server" => "server-one"),
    ("core-service" => "platform-mbean"),
    ("type" => "memory-pool"),
    ("name" => "PS_Old_Gen")

read docker container stats

docker stats -a
 
CONTAINER           CPU %               MEM USAGE / LIMIT     MEM %               NET I/O               BLOCK I/O
2706e4c364e4        0.00%               19.53 MB / 3.968 GB   0.49%               7.927 kB / 1.145 kB   27.69 MB / 0 B
2a4f6a915e6a        0.00%               1.2 MB / 3.968 GB     0.03%               0 B / 0 B             1.23 MB / 0 B
58bad82a9cc5        0.00%               1.2 MB / 3.968 GB     0.03%               0 B / 0 B             1.23 MB / 0 B
5ddb4ab61e06        0.00%               0 B / 0 B             0.00%               0 B / 0 B             0 B / 0 B
8074769d8920        0.00%               0 B / 0 B             0.00%               0 B / 0 B             0 B / 0 B
8be2ab53a038        0.00%               0 B / 0 B             0.00%               0 B / 0 B             0 B / 0 B
910894575d7f        0.00%               0 B / 0 B             0.00%               0 B / 0 B             0 B / 0 B
94b1b84531b5        0.00%               0 B / 0 B             0.00%               0 B / 0 B             0 B / 0 B
9f60c0752dd9        0.00%               0 B / 0 B             0.00%               0 B / 0 B             0 B / 0 B
b32fa90fe8bc        0.00%               0 B / 0 B             0.00%               0 B / 0 B             0 B / 0 B
b8f543e79882        0.00%               0 B / 0 B             0.00%               0 B / 0 B             0 B / 0 B
cf6cf57a53e2        0.00%               0 B / 0 B             0.00%               0 B / 0 B             0 B / 0 B
dd410adfc681        0.00%               1.196 MB / 3.968 GB   0.03%               0 B / 0 B             1.23 MB / 0 B
f68d317bddbc        0.00%               0 B / 0 B             0.00%               0 B / 0 B             0 B / 0



sudo docker stats 2706e4c364e4

CONTAINER           CPU %               MEM USAGE / LIMIT     MEM %               NET I/O               BLOCK I/O
2706e4c364e4        0.05%               19.53 MB / 3.968 GB   0.49%               7.927 kB / 1.145 kB   27.69 MB / 0 B

środa, 10 sierpnia 2016

deploy config jenkins + tomcat

1. install right plugin



2. configure jenkins job:

in such configuration jenkins take the war file from: /var/lib/jenkins/workspace/get_file

3. sucess

Started by user marek borkowski
[EnvInject] - Loading node environment variables.
Building in workspace /var/lib/jenkins/workspace/get_file
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/bormarek/test # timeout=10
Fetching upstream changes from https://github.com/bormarek/test
 > git --version # timeout=10
 > git -c core.askpass=true fetch --tags --progress https://github.com/bormarek/test +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 201dacd91f299e0eb88de6203cb7e7da4c19a528 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 201dacd91f299e0eb88de6203cb7e7da4c19a528
 > git rev-list 201dacd91f299e0eb88de6203cb7e7da4c19a528 # timeout=10
Deploying /var/lib/jenkins/workspace/get_file/sample.war to container Tomcat 7.x Remote
  Redeploying [/var/lib/jenkins/workspace/get_file/sample.war]
  Undeploying [/var/lib/jenkins/workspace/get_file/sample.war]
  Deploying [/var/lib/jenkins/workspace/get_file/sample.war]
Finished: SUCCESS

4. verification



create dir and go into it

marek@ubuntu:/tmp$ mkdir nginx && cd $_ marek@ubuntu:/tmp/nginx$ pwd /tmp/nginx

Jenkins - where the git repo are put

SukcesLogi konsoli

Started by user marek borkowski
[EnvInject] - Loading node environment variables.
Building in workspace /var/lib/jenkins/workspace/test_git
Cloning the remote Git repository
Cloning repository https://github.com/bormarek/go
 > git init /var/lib/jenkins/workspace/test_git # timeout=10
Fetching upstream changes from https://github.com/bormarek/go
 > git --version # timeout=10
 > git -c core.askpass=true fetch --tags --progress https://github.com/bormarek/go +refs/heads/*:refs/remotes/origin/*
 > git config remote.origin.url https://github.com/bormarek/go # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url https://github.com/bormarek/go # timeout=10
Fetching upstream changes from https://github.com/bormarek/go
 > git -c core.askpass=true fetch --tags --progress https://github.com/bormarek/go +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 835271417788d0bf08adf28aedebf7ce5c2e1eaf (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 835271417788d0bf08adf28aedebf7ce5c2e1eaf
First time build. Skipping changelog.
Finished: SUCCESS

marek@ubuntu:/var/lib/jenkins/workspace/test_git$ ls -ltr
razem 31112
-rw-r--r-- 1 jenkins jenkins     124 sie 10 15:01 StructTest.go
-rw-r--r-- 1 jenkins jenkins     301 sie 10 15:01 StructMet.go
-rwxr-xr-x 1 jenkins jenkins      12 sie 10 15:01 README.md
-rw-r--r-- 1 jenkins jenkins     177 sie 10 15:01 FuncTest.go
-rwxr-xr-x 1 jenkins jenkins     185 sie 10 15:01 ArrayElements.go
-rw-r--r-- 1 jenkins jenkins     155 sie 10 15:01 arr.go
-rw-r--r-- 1 jenkins jenkins     222 sie 10 15:01 args.go
-rwxr-xr-x 1 jenkins jenkins 2253776 sie 10 15:01 args
-rw-r--r-- 1 jenkins jenkins     403 sie 10 15:01 c.pub
-rwxr-xr-x 1 jenkins jenkins     448 sie 10 15:01 cmdLine.go
-rw-r--r-- 1 jenkins jenkins     334 sie 10 15:01 checkIfFile.go
-rw-r--r-- 1 jenkins jenkins    1679 sie 10 15:01 c
-rw-r--r-- 1 jenkins jenkins     134 sie 10 15:01 arrayTest.go
-rw-r--r-- 1 jenkins jenkins     193 sie 10 15:01 array.go
-rwxr-xr-x 1 jenkins jenkins 2253760 sie 10 15:01 array
-rw-r--r-- 1 jenkins jenkins     125 sie 10 15:01 errors.go
-rwxr-xr-x 1 jenkins jenkins     286 sie 10 15:01 envVar.go
-rwxr-xr-x 1 jenkins jenkins     223 sie 10 15:01 commandExec.go
-rwxr-xr-x 1 jenkins jenkins 2669552 sie 10 15:01 commandExec
-rw-r--r-- 1 jenkins jenkins     113 sie 10 15:01 forLoop.go
-rw-r--r-- 1 jenkins jenkins     106 sie 10 15:01 forCont.go
-rw-r--r-- 1 jenkins jenkins     309 sie 10 15:01 fileInfo.go
-rwxr-xr-x 1 jenkins jenkins 2393920 sie 10 15:01 fileInfo
-rwxr-xr-x 1 jenkins jenkins     127 sie 10 15:01 helloWorld.go
-rwxr-xr-x 1 jenkins jenkins   15520 sie 10 15:01 git-credential-osxkeychain
-rw-r--r-- 1 jenkins jenkins     109 sie 10 15:01 forWhile.go
-rw-r--r-- 1 jenkins jenkins     194 sie 10 15:01 forRange.go
-rwxr-xr-x 1 jenkins jenkins 2253824 sie 10 15:01 forRange
-rwxr-xr-x 1 jenkins jenkins     141 sie 10 15:01 randPerm.go
-rwxr-xr-x 1 jenkins jenkins     141 sie 10 15:01 randInt.go
-rwxr-xr-x 1 jenkins jenkins     222 sie 10 15:01 printfPractice.go
-rw-r--r-- 1 jenkins jenkins     603 sie 10 15:01 netHttp.go
-rw-r--r-- 1 jenkins jenkins     195 sie 10 15:01 ifSqrt.go
-rwxr-xr-x 1 jenkins jenkins 2258080 sie 10 15:01 ifSqrt
-rwxr-xr-x 1 jenkins jenkins     287 sie 10 15:01 readFile.go
-rwxr-xr-x 1 jenkins jenkins 2462848 sie 10 15:01 readFile
-rw-r--r-- 1 jenkins jenkins      57 sie 10 15:01 vertex.go
-rw-r--r-- 1 jenkins jenkins     100 sie 10 15:01 var.go
-rw-r--r-- 1 jenkins jenkins     146 sie 10 15:01 varCalc.go
-rw-r--r-- 1 jenkins jenkins     666 sie 10 15:01 serveHttp.go
-rwxr-xr-x 1 jenkins jenkins 7569628 sie 10 15:01 serveHttp
-rwxr-xr-x 1 jenkins jenkins     325 sie 10 15:01 writeFile.go
-rw-r--r-- 1 jenkins jenkins     392 sie 10 15:01 webHelloWorld.go
-rwxr-xr-x 1 jenkins jenkins 7565260 sie 10 15:01 webHelloWorld

how to test github connection

1. ssh-keygen -t rsa -b 4096 -C "bormarek@gmail.com"

2. root@ubuntu:~# eval "$(ssh-agent -s)"
Agent pid 22355

3. root@ubuntu:~# ssh-add ~/.ssh/id_rsa
Identity added: /home/marek/.ssh/id_rsa (/home/marek/.ssh/id_rsa)

4. root@ubuntu:~# ssh -T git@github.com
Hi bormarek! You've successfully authenticated, but GitHub does not provide shell access.


how to check what is going on inside of docker container

root@ubuntu:~# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                              NAMES
0a41e947e925        wordpress:latest    "/entrypoint.sh apach"   10 minutes ago      Up 10 minutes       0.0.0.0:8000->80/tcp               wordpress_wordpress_1
8526889870a9        mysql:5.7           "docker-entrypoint.sh"   10 minutes ago      Up 10 minutes       3306/tcp                           wordpress_db_1
e01674b264b4        nginx               "nginx -g 'daemon off"   About an hour ago   Up 51 minutes       80/tcp, 443/tcp                    nginx_nginx_1
69581c420e2b        rancher/server      "/usr/bin/s6-svscan /"   12 hours ago        Up About an hour    3306/tcp, 0.0.0.0:8080->8080/tcp   silly_mclean

root@ubuntu:~# docker exec -it 0a41e947e925 /bin/bash

root@0a41e947e925:/var/www/html# ls
index.php    readme.html      wp-admin            wp-comments-post.php  wp-config.php  wp-cron.php  wp-links-opml.php  wp-login.php  wp-settings.php  wp-trackback.php
license.txt  wp-activate.php  wp-blog-header.php  wp-config-sample.php  wp-content     wp-includes  wp-load.php        wp-mail.php   wp-signup.php    xmlrpc.php

poniedziałek, 8 sierpnia 2016

very simple nginx loadbalancer

cat /etc/nginx/sites-available/proxy
       
upstream 192.168.1.29 {
            server 10.0.3.36:80  weight=2;
            server 10.0.3.113:80 weight=3;
            server 10.0.3.186:80 weight=3;
            server 10.0.3.168:80 weight=4;
            server 10.0.3.193:80 weight=4;
            server 10.0.3.130:80 weight=3;
        }

        server {
            listen 80;
            server_name ubuntu;
            location / {
                proxy_pass http://192.168.1.29;
            }
        }


create docker tomcat container with app deployment Dockerfile

1. root@ubuntu:~#
cat Dockerfile
FROM tomcat
ADD sample.war /usr/local/tomcat/webapps/

2. run command:

root@ubuntu:~# docker build --tag=tomcat_app .

Sending build context to Docker daemon 316.1 MB
Step 1 : FROM tomcat
 ---> 25e98610c7d0
Step 2 : ADD sample.war /usr/local/tomcat/webapps/
 ---> e063fb60dcb7
Removing intermediate container 137ac3730916
Successfully built e063fb60dcb7

3. check docker images:


root@ubuntu:~# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED              SIZE
tomcat_app                latest              e063fb60dcb7        10 seconds ago       359.2 MB


4. verification
docker inspect -f '{{ .NetworkSettings.IPAddress }}' b804ab2e870d

w3m http://172.17.0.2:8080/sample




niedziela, 7 sierpnia 2016

how to check docker container ip adress

root@ubuntu:~# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                    NAMES
c2d8b8ad7dbf        wildfly             "/opt/jboss/wildfly/b"   About a minute ago   Up About a minute   0.0.0.0:8080->8080/tcp   elated_meitner
root@ubuntu:~# docker inspect -f '{{ .NetworkSettings.IPAddress }}' c2d8b8ad7dbf
172.17.0.2

backup and restore docker container

# docker save -o ~/container1.tar container1
[root@localhost marek]# ls -l ~/container1.tar
-rw-r--r--. 1 root root 131017216 Jun 14 20:31 /root/container1.tar

docker load -i /root/container1.tar
docker images

how to forced remove docker image

root@ubuntu:~# docker rmi 71d87edfa7f5
Failed to remove image (71d87edfa7f5): Error response from daemon: conflict: unable to delete 71d87edfa7f5 (must be forced) - image is referenced in one or more repositories

root@ubuntu:~# docker rmi -f 71d87edfa7f5
Untagged: wildfly-app:latest
Untagged: wildfly-helloworld:latest
Deleted: sha256:71d87edfa7f5ad7ef5b15521bd6a8cc6f368af5ac7fc6a44165d904ac997b55d
Deleted: sha256:b1992e989159199daf9fba21fff4713e056d85e07e6c1a9409155a6e73ae07ec
Deleted: sha256:dcdf3e6f385e7f93329e71ddd6b93ef81256c195289425efdde6c20f09bd4d99
Deleted: sha256:e1009af06161e03ddfb44414c54adf5c213a51bcafdb4ee943033ee329f5c469

sobota, 30 lipca 2016

check ip via ipinfo

root@ubuntu:~# curl ipinfo.io/212.77.98.9
{
  "ip": "212.77.98.9",
  "hostname": "www.wp.pl",
  "city": "Warzachewka Polska",
  "region": "Kujawsko-Pomorskie",
  "country": "PL",
  "loc": "52.5931,19.0894",
  "org": "AS12827 Wirtualna Polska S.A."
}

"city": "Warzachewka Polska", ???

Really?


czwartek, 28 lipca 2016

poniedziałek, 25 lipca 2016

how to run docker container with forwarded ports

docker run -p 80:80 -td ubuntu_nginx_full

root@ubuntu:~# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS                NAMES
12b043cfda9c        ubuntu_nginx_full   "/bin/bash"         About a minute ago   Up About a minute   0.0.0.0:80->80/tcp   fervent_meninsky

poniedziałek, 18 lipca 2016

niedziela, 17 lipca 2016

very simple reverse proxy nginx

apt-get install nginx
unlink /etc/nginx/sites-enabled/default

/etc/nginx/sites-available/tomcat

server {
        listen 80;
        location / {
             proxy_pass http://192.168.1.12:8080/sample/;
        }
}

verification:

marek@lati:~$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful



sobota, 16 lipca 2016

how to add jmx support to tomcat

root@ubuntu-xenial:/usr/share/tomcat7/bin#

vi setenv.sh
export JAVA_OPTS="-Dcom.sun.management.jmxremote=true
                  -Dcom.sun.management.jmxremote.port=9090
                  -Dcom.sun.management.jmxremote.ssl=false
                  -Dcom.sun.management.jmxremote.authenticate=false
                  -Djava.rmi.server.hostname=192.168.1.10"


systemctl restart tomcat7.service

czwartek, 14 lipca 2016

Ansible playbook

---
- hosts: all
  sudo: yes
  tasks:
    - name: install tomcat
      apt: name=tomcat7 update_cache=yes state=latest
    - name: install tomcat-admin
      apt: name=tomcat7-admin update_cache=yes state=latest
    - name: install tomcat-examples
      apt: name=tomcat7-examples update_cache=yes state=latest
    - name: install tomcat7-admin
      apt: name=tomcat7-admin update_cache=yes state=latest
    - name: install tomcat7-docs
      apt: name=tomcat7-docs update_cache=yes state=latest
    - name: install libxml2-dev
      apt: name=libxml2-dev update_cache=yes state=latest
    - name: install apache benchmark
      apt: name=apache2-utils update_cache=yes state=latest
    - name: echo
      shell: echo Hello World!! > /tmp/hello_workd
    - name: deploy sample test application
      shell: cd /tmp/ && wget https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war && cp sample.war /var/lib/tomcat7/webapps/
    - name: install apache2
      apt: name=apache2 update_cache=yes state=latest
    - name: get tar.gz of tomcat7
      shell: wget http://ftp.piotrkosoft.net/pub/mirrors/ftp.apache.org/tomcat/tomcat-7/v7.0.70/bin/apache-tomcat-7.0.70.tar.gz
    - name: get zabbix repo
      shell: wget http://repo.zabbix.com/zabbix/3.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.0-1+trusty_all.deb && dpkg -i zabbix-release_3.0-1+trusty_all.deb && apt-get update -y && apt-get install zabbix-agent -y
    - name: restart tomcat service
      shell: /etc/init.d/tomcat7 restart
    - name: configure tomcat users
      shell: echo
    - name: enabled mod_rewrite
      apache2_module: name=rewrite state=present
      notify:
        - restart apache2
  handlers:
    - name: restart apache2
      service: name=apache2 state=restarted


marek@debian:~$ ansible-playbook playbook.yml --ask-sudo-pass
sudo password:

PLAY [all] ********************************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.1.66]

TASK: [install tomcat] ********************************************************
ok: [192.168.1.66]

TASK: [install tomcat-admin] **************************************************
ok: [192.168.1.66]

TASK: [install tomcat-examples] ***********************************************
ok: [192.168.1.66]

TASK: [install tomcat7-admin] *************************************************
ok: [192.168.1.66]

TASK: [install tomcat7-docs] **************************************************
ok: [192.168.1.66]

TASK: [install libxml2-dev] ***************************************************
ok: [192.168.1.66]

TASK: [install apache benchmark] **********************************************
ok: [192.168.1.66]

TASK: [echo] ******************************************************************
changed: [192.168.1.66]

TASK: [deploy sample test application] ****************************************
changed: [192.168.1.66]

TASK: [install apache2] *******************************************************
ok: [192.168.1.66]

TASK: [get tar.gz of tomcat7] *************************************************
changed: [192.168.1.66]

TASK: [get zabbix repo] *******************************************************
changed: [192.168.1.66]

TASK: [restart tomcat service] ************************************************
changed: [192.168.1.66]

TASK: [configure tomcat users] ************************************************
changed: [192.168.1.66]

TASK: [enabled mod_rewrite] ***************************************************
ok: [192.168.1.66]

PLAY RECAP ********************************************************************
192.168.1.66               : ok=16   changed=6    unreachable=0    failed=0




Quick tip: Exposing your local web server





awesome tool :) !!!

środa, 29 czerwca 2016

forced remove docker images

┌─[ubuntu]─[~/docker/centos]
└──╼ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED                                                                                                                          SIZE
<none>              <none>              a9c0eefa1525        2 minutes ago                                                                                                                    400.9 MB
centos              7                   904d6c400333        3 weeks ago                                                                                                                      196.8 MB
 
┌─[✗]─[ubuntu]─[~/docker/centos]
└──╼ docker rmi a9c0eefa1525 -f
Failed to remove image (a9c0eefa1525): Error response from daemon: conflict: unable to delete a9c0eefa1525 (must be forced) - image is being used by stopped container 28fcdd89e896
Failed to remove image (-f): Error response from daemon: No such image: -f:latest

┌─[✗]─[ubuntu]─[~/docker/centos]
└──╼ docker rmi -f a9c0eefa1525
Deleted: sha256:a9c0eefa15257ca73c4df58f47934129238affcdf9f920b149847c299ed3cf17
Deleted: sha256:d1fc541edbb0104ec34ac12484495096c7153ec8cfe98a5fc0b7e4809bc1cd44
Deleted: sha256:dcae9a0cc9da5ae5ad705da038c2dcc65705944f97b9e21982994abd13676ec7


┌─[ubuntu]─[~/docker/centos]
└──╼ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              7                   904d6c400333        3 weeks ago         196.8 MB
┌─[ubuntu]─[~/docker/centos]
└──╼ docker rmi -f 904d6c400333
Untagged: centos:7
Deleted: sha256:904d6c400333c03490f618654231344a9129cd4946049dc2878ce53558e7b816

czwartek, 23 czerwca 2016

Atom best editor -- how to run command in atom editor?

Normally atom is just a editor but if we want we can create IDE for our purpose.
about atom:


1. install

marek: ~/Documents/dev/ruby $ apm install atom-runner

Installing atom-runner to /Users/marek/.atom/packages ✓

apm is: atom package manager

2. each code you can execute by pressing ctrl + r(alt +r) in linux windows
to kill current running process - ctrl+shift+C

output will be showed on the right site of atom window

środa, 22 czerwca 2016

Run command threw Ansible

┌─[✗]─[marek@ubuntu]─[/etc/ansible]
└──╼ ansible all -a "dnf install docker -y" -u root

192.168.1.11 | SUCCESS | rc=0 >>
Last metadata expiration check: 0:12:33 ago on Wed Jun 22 23:31:30 2016.
Dependencies resolved.
================================================================================
 Package                      Arch   Version                      Repository
                                                                           Size
================================================================================
Installing:
 audit-libs-python3           x86_64 2.5.2-1.fc24                 fedora   95 k
 checkpolicy                  x86_64 2.5-2.fc24                   fedora  301 k
 docker                       x86_64 2:1.10.3-19.gitee81b72.fc24  updates 6.7 M
 docker-selinux               x86_64 2:1.10.3-19.gitee81b72.fc24  updates  72 k
 docker-v1.10-migrator        x86_64 2:1.10.3-19.gitee81b72.fc24  updates 1.9 M
 libcgroup                    x86_64 0.41-8.fc24                  fedora   67 k
 libsemanage-python3          x86_64 2.5-2.fc24                   fedora  112 k
 policycoreutils-python-utils x86_64 2.5-5.fc24                   fedora  215 k
 policycoreutils-python3      x86_64 2.5-5.fc24                   fedora  1.8 M
 setools-libs                 x86_64 3.3.8-10.fc24                fedora  561 k
 sqlite                       x86_64 3.11.0-3.fc24                fedora  486 k

Transaction Summary
================================================================================
Install  11 Packages

Total download size: 12 M
Installed size: 43 M
Downloading Packages:
--------------------------------------------------------------------------------
Total                                           2.0 MB/s |  12 MB     00:06
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Installing  : docker-v1.10-migrator-2:1.10.3-19.gitee81b72.fc24.x86_6    1/11
  Installing  : libcgroup-0.41-8.fc24.x86_64                               2/11
  Installing  : sqlite-3.11.0-3.fc24.x86_64                                3/11
  Installing  : setools-libs-3.3.8-10.fc24.x86_64                          4/11
  Installing  : libsemanage-python3-2.5-2.fc24.x86_64                      5/11
  Installing  : checkpolicy-2.5-2.fc24.x86_64                              6/11
  Installing  : audit-libs-python3-2.5.2-1.fc24.x86_64                     7/11
  Installing  : policycoreutils-python3-2.5-5.fc24.x86_64                  8/11
  Installing  : policycoreutils-python-utils-2.5-5.fc24.x86_64             9/11
  Installing  : docker-selinux-2:1.10.3-19.gitee81b72.fc24.x86_64         10/11
  Installing  : docker-2:1.10.3-19.gitee81b72.fc24.x86_64                 11/11
  Verifying   : docker-2:1.10.3-19.gitee81b72.fc24.x86_64                  1/11
  Verifying   : docker-selinux-2:1.10.3-19.gitee81b72.fc24.x86_64          2/11
  Verifying   : policycoreutils-python-utils-2.5-5.fc24.x86_64             3/11
  Verifying   : policycoreutils-python3-2.5-5.fc24.x86_64                  4/11
  Verifying   : audit-libs-python3-2.5.2-1.fc24.x86_64                     5/11
  Verifying   : checkpolicy-2.5-2.fc24.x86_64                              6/11
  Verifying   : libsemanage-python3-2.5-2.fc24.x86_64                      7/11
  Verifying   : setools-libs-3.3.8-10.fc24.x86_64                          8/11
  Verifying   : sqlite-3.11.0-3.fc24.x86_64                                9/11
  Verifying   : libcgroup-0.41-8.fc24.x86_64                              10/11
  Verifying   : docker-v1.10-migrator-2:1.10.3-19.gitee81b72.fc24.x86_6   11/11

Installed:
  audit-libs-python3.x86_64 2.5.2-1.fc24
  checkpolicy.x86_64 2.5-2.fc24
  docker.x86_64 2:1.10.3-19.gitee81b72.fc24
  docker-selinux.x86_64 2:1.10.3-19.gitee81b72.fc24
  docker-v1.10-migrator.x86_64 2:1.10.3-19.gitee81b72.fc24
  libcgroup.x86_64 0.41-8.fc24
  libsemanage-python3.x86_64 2.5-2.fc24
  policycoreutils-python-utils.x86_64 2.5-5.fc24
  policycoreutils-python3.x86_64 2.5-5.fc24
  setools-libs.x86_64 3.3.8-10.fc24
  sqlite.x86_64 3.11.0-3.fc24

Complete!

wtorek, 21 czerwca 2016

Ansible playbook for ubuntu "clients" server

ansible-playbook ubuntu.yml -v --user=marek --extra-vars "ansible_sudo_pass=<your_password>"


[root@centos ansible]# cat ubuntu.yml
---
- name: Hello Ansible - quick start
  hosts: ubuntu
  user: marek
  sudo: yes

  tasks:
    - name: Hello server
      shell: date >> now.txt

Ansible hello world playbook

The more advanced option to use with ansible are playbook:

very simple example:
---
- name: Hello Ansible - quick start
  hosts: fedora
  user: root
  sudo: no

  tasks:
    - name: Hello server
      shell: date >> now.txt
~
~

[root@centos ansible]# ansible-playbook setup.yml -v
No config file found; using defaults
[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and make sure become_method is 'sudo' (default).
This feature will be removed in a future release. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

PLAY [Hello Ansible - quick start] *********************************************

TASK [setup] *******************************************************************
ok: [192.168.1.11]
ok: [192.168.1.14]

TASK [Hello server] ************************************************************
changed: [192.168.1.11] => {"changed": true, "cmd": "date >> now.txt", "delta": "0:00:00.002414", "end": "2016-06-21 23:03:38.561068", "rc": 0, "start": "2016-06-21 23:03:38.558654", "stderr": "", "stdout": "", "stdout_lines": [], "warnings": []}
changed: [192.168.1.14] => {"changed": true, "cmd": "date >> now.txt", "delta": "0:00:00.002988", "end": "2016-06-21 23:03:36.163002", "rc": 0, "start": "2016-06-21 23:03:36.160014", "stderr": "", "stdout": "", "stdout_lines": [], "warnings": []}

PLAY RECAP *********************************************************************
192.168.1.11               : ok=2    changed=1    unreachable=0    failed=0
192.168.1.14 

The basics of Ansible

The Ansible is written in python tool to make the admin things more clear and comfortable.
We dont need any app server any client only python and ssh. Looks great - well .... we will see


[root@centos ansible]# ansible fedora -m shell -a "dnf install python-pip -y"
192.168.1.11 | SUCCESS | rc=0 >>
Ostatnio sprawdzono ważność metadanych: 1:25:40 temu w dniu Tue Jun 21 21:11:10 2016.
Rozwiązano zależności.
Nie ma niczego do zrobienia.
Ukończono.Pakiet python-pip-8.0.2-1.fc24.noarch jest już zainstalowany, pomijanie.

192.168.1.14 | SUCCESS | rc=0 >>
Ostatnio sprawdzono ważność metadanych: 0:34:44 temu w dniu Tue Jun 21 22:02:03 2016.
Rozwiązano zależności.
Nie ma niczego do zrobienia.
Ukończono.Pakiet python-pip-7.1.0-1.fc23.noarch jest już zainstalowany, pomijanie.


description:

Usage: ansible <host-pattern> [options]

fedora / [all] - group that we will check / all for all groups to change it or just check you need to find file:

hosts in ansible /etc/ dir

[root@centos ansible]# cat hosts
[fedora]
192.168.1.14
192.168.1.11
[ubuntu]
192.168.1.19


  -m MODULE_NAME, --module-name=MODULE_NAME
                        module name to execute (default=command)

  -a MODULE_ARGS, --args=MODULE_ARGS
                        module arguments


login without password - ssh config

[root@centos ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
8f:8d:89:3b:3b:ed:80:48:a6:d5:e1:56:b2:ce:e0:0c root@centos
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|    o .          |
|   o =           |
|E = =   S        |
| O * . . *       |
|. + + o.+ o      |
|      oo.        |
|      o=.        |
+-----------------+
[root@centos ~]#
[root@centos ~]#
[root@centos ~]#
[root@centos ~]#
[root@centos ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.1.11
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter                                                                                                              out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompt                                                                                                             ed now it is to install the new keys
root@192.168.1.11's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.1.11'"
and check to make sure that only the key(s) you wanted were added.

[root@centos ~]# ssh 192.168.1.11
Last login: Tue Jun 21 22:04:45 2016 from 192.168.1.21
[root@fedora24 ~]#

sobota, 11 czerwca 2016

C Alphabet vs Java Alphabet

#include <stdio.h>
int main()
{
    int litera;
    for(litera = 'A'; litera <= 'Z'; litera++)
    {
        printf("%c\n",litera);
    }
    return 0;
}

the same case in java:
public class BattleShip {
    public static void main(String[] args){
        for(int i=0;i<26;i++){
            System.out.print((char)('A' + i));
        }
    }
}

how to get full string from user c++

void getMessage(string name)
{
    cout << "enter your name: ";
    getline(cin, name);
    cout << "Hello " << name << endl;
}

środa, 8 czerwca 2016

Java Dec to (bin,hex and oct) converter

public class IntToBin {
    public static void main(String[] args){
        java.util.Scanner scIn = new java.util.Scanner(System.in);
        System.out.print("Enter int: ");
        int IntDig = scIn.nextInt();

        System.out.println("bin: "+Integer.toBinaryString(IntDig));
        System.out.println("hex: "+Integer.toHexString(IntDig));
        System.out.println("octal: "+Integer.toOctalString(IntDig));


    }
}

wtorek, 7 czerwca 2016

check memory details via python script on mac os x

#!/usr/bin/python

import subprocess
import re

# Get process info
ps = subprocess.Popen(['ps', '-caxm', '-orss,comm'], stdout=subprocess.PIPE).communicate()[0]
vm = subprocess.Popen(['vm_stat'], stdout=subprocess.PIPE).communicate()[0]

# Iterate processes
processLines = ps.split('\n')
sep = re.compile('[\s]+')
rssTotal = 0 # kB
for row in range(1,len(processLines)):
    rowText = processLines[row].strip()
    rowElements = sep.split(rowText)
    try:
        rss = float(rowElements[0]) * 1024
    except:
        rss = 0 # ignore...
    rssTotal += rss

# Process vm_stat
vmLines = vm.split('\n')
sep = re.compile(':[\s]+')
vmStats = {}
for row in range(1,len(vmLines)-2):
    rowText = vmLines[row].strip()
    rowElements = sep.split(rowText)
    vmStats[(rowElements[0])] = int(rowElements[1].strip('\.')) * 4096

print 'Wired Memory:\t\t%d MB' % ( vmStats["Pages wired down"]/1024/1024 )
print 'Active Memory:\t\t%d MB' % ( vmStats["Pages active"]/1024/1024 )
print 'Inactive Memory:\t%d MB' % ( vmStats["Pages inactive"]/1024/1024 )
print 'Free Memory:\t\t%d MB' % ( vmStats["Pages free"]/1024/1024 )
print 'Real Mem Total (ps):\t%.3f MB' % ( rssTotal/1024/1024 )





MacBook-Pro-Marek:python marek$ python sys.py 
Wired Memory: 2239 MB
Active Memory: 6772 MB
Inactive Memory: 4624 MB
Free Memory: 1433 MB

Real Mem Total (ps): 8770.777 MB