poniedziałek, 28 grudnia 2015

check all host's in network

┌─[marek@lati]─[~/projekty/python]
└──╼ nmap -sP 192.168.1.0/24

Starting Nmap 6.47 ( http://nmap.org ) at 2015-12-28 23:18 CET
Nmap scan report for 192.168.1.1
Host is up (0.0045s latency).
Nmap scan report for 192.168.1.16
Host is up (0.0011s latency).
Nmap scan report for 192.168.1.47
Host is up (0.059s latency).
Nmap scan report for 192.168.1.213
Host is up (0.00021s latency).
Nmap done: 256 IP addresses (4 hosts up) scanned in 2.71 seconds


we can also use:

[root@virt ~]# arp-scan --interface=enp0s9 --localnet
Interface: enp0s9, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.8.4 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
192.168.1.1     a0:c5:62:72:c6:00       (Unknown)
192.168.1.16    34:7a:60:d4:e4:43       (Unknown)
192.168.1.54    a4:34:d9:46:9b:c3       (Unknown)
192.168.1.243   78:40:e4:f9:a5:32       (Unknown)

4 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.8.4: 256 hosts scanned in 1.906 seconds (134.31 hosts/sec). 4 responded





print lines perl linux

┌─[marek@lati]─[/tmp/test]
└──╼ perl -ne 'print if 1..3' /etc/passwd

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin

print lines from 1 to 3



delete except some file

┌─[marek@lati]─[/tmp/test]
└──╼ ll
razem 0
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 test.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 marek.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 gosia.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 wiktor.html

┌─[marek@lati]─[/tmp/test]
└──╼ rm !(*.html) #delete all except html files

┌─[marek@lati]─[/tmp/test]
└──╼ ls -ltr
razem 0
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 test.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 wiktor.html
┌─[marek@lati]─[/tmp/test]



┌─[marek@lati]─[/tmp/test]
└──╼ ll
razem 0
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 test.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:38 wiktor.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 2.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 1.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 3.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 5.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 4.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 6.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 8.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 7.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 9.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 10.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 1.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 3.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 2.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 4.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 5.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 7.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 6.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 8.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 9.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 10.txt
┌─[marek@lati]─[/tmp/test]
└──╼ rm !(10.txt|9.txt|2.html) #delete all except files in bracket

┌─[marek@lati]─[/tmp/test]
└──╼ ls -ltr
razem 0
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 2.html
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 9.txt
-rw-rw-r-- 1 marek marek 0 gru 28 20:40 10.txt



calc bc - terminal calc

┌─[marek@lati]─[~]
└──╼ for i in `seq 1 50`;do echo "2^$i" | bc; done
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
131072
262144
524288
1048576
2097152
4194304
8388608
16777216
33554432
67108864
134217728
268435456
536870912
1073741824
2147483648
4294967296
8589934592
17179869184
34359738368
68719476736
137438953472
274877906944
549755813888
1099511627776
2199023255552
4398046511104
8796093022208
17592186044416
35184372088832
70368744177664
140737488355328
281474976710656
562949953421312
1125899906842624

piątek, 11 grudnia 2015

how to customize ps command

ps -eo user,comm,pid,ppid,%mem --sort -%mem | head -20

output:

┌─[marek@lati]─[~]
└──╼ ps -eo user,comm,pid,ppid,%mem --sort -%mem | head -20
USER     COMMAND           PID  PPID %MEM
marek    chrome                   20783 19909  6.5
marek    chrome                   19721 20801  2.4
marek    chrome                   17491 20801  1.8
marek    chrome                   32489 20801  1.4
marek    chrome                   17216 20801  1.3
marek    compiz                   20317 20109  1.3
marek    firefox                    28810 19909  1.3
marek    chrome                   6114 20801  1.2
marek    chrome                   20970 20801  1.0
marek    chrome                   20905 20801  1.0
marek    chrome                   27848 20801  1.0
marek    chrome                   17174 20801  0.9
marek    chrome                   32512 20801  0.7
marek    chrome                   31889 20801  0.6
marek    chrome                   32173 20801  0.6
marek    chrome                   17194 20801  0.6
marek    chrome                   20879 20783  0.5
marek    gnome-keyring-d   19907     1  0.5

sobota, 28 listopada 2015

how to find file with permission 775 and change them to 777 for example

find . -perm 775 -exec chmod 777 {} \;

Enable Trim ubuntu

gksudo gedit /etc/cron.daily/trim
and enter the following:

#!/bin/sh
LOG=/var/log/trim.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG
fstrim -v /home >> $LOG


sudo chmod +x /etc/cron.daily/trim

how to kill all app process

└──╼ pidof chrome
4027 4012 3998 3984 3924 3283 3251 3199 3117 3078 2772 2757 2752 2737 2733 2699 2660 2654 2582 2568 2556

for i in `pidof chrome`; do kill -9 $i; done

czwartek, 26 listopada 2015

Docker Hello World

└──╼ docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from hello-world
3f12c794407e: Pull complete
975b84d108f1: Pull complete
hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7
Status: Downloaded newer image for hello-world:latest

Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/userguide/

niedziela, 22 listopada 2015

Full TCP echo server build base on nc

ncat -v -l -p 5555 -c 'while true; do read i && echo [echo] $i; done'
while true; do nc -l 8888 < page.html; done

sobota, 14 listopada 2015

Types of killings - Kill Linux process

 marek  ~  kill -l
 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX

How to list all user process in linux

pgrep -u marek -l

 marek  ~  pgrep -u marek -l
1548 systemd
1550 (sd-pam)
1553 sh
1560 dbus-launch
1561 dbus-daemon
1626 imsettings-daem
1630 gvfsd
1637 xfconfd
1700 ssh-agent
1724 xfce4-session
1729 gpg-agent
1731 xfwm4
1735 xfce4-panel
1737 Thunar
1739 xfdesktop
1740 nm-applet
1741 polkit-gnome-au
1742 xscreensaver
1745 xfsettingsd
...
...

środa, 4 listopada 2015

Unix File Permission's

 
File Permissions:
 
r=4
w=2
x=1
in every group. Your example is 6(r+w=4+2)4(r=4)4(r=4).

-rw-r--r-- 1 root root 436644612 Nov  4 12:30 jbfsw-60-6.0.0.102.rpm

4+2/4/4

chmod 644 jbfsw-60-6.0.0.102.rpm

niedziela, 1 listopada 2015

change xterm to terminal in geany gnome and xfce

Its good. default geany teminal setting is-
xterm -e "/bin/sh %c"
change it to-
gnome-terminal -x "/bin/sh" %c
It works, 100%
xfce:

/usr/bin/exo-open --launch TerminalEmulator "/bin/sh %c"

How to serve file from different location - python http

pushd /x01/tecmint/; python –m SimpleHTTPServer 9999; popd;

sobota, 10 października 2015

python args support

import sys
import os


print "the script name is: ",sys.argv[0]
os.system('clear')

if len(sys.argv) > 1:
print "there are", len(sys.argv)-1,"args"
we = raw_input("Do you want to list args: ")
if (we == 'yes'):
for arg in sys.argv[1:]:
print arg
else:
print "the end"
else:
print "there are no args"


#!/usr/bin/python

import sys

if len(sys.argv) <= 1:
print "no args"
else:
total = len(sys.argv)
cmdargs = str(sys.argv)

print "total: %d" % total
print "args list: %s" % cmdargs

czwartek, 8 października 2015

reversed ArrayList java

Alternative solution for: Collections.reverse(list);

package Arrays;

import java.util.ArrayList;

public class ReverseArrayList
{
public static void draw(int l)
{
for(int i=0;i<=l;i++)
{
System.out.print("-=-");
}
System.out.println();
}
public static void main(String[] args)
{
ArrayList<String> list = new ArrayList<>();
list.add("m");
list.add("a");
list.add("r");
list.add("e");
list.add("k");

System.out.println(list);
draw(10);
for(int i= list.size()-1; i>=0; i--)
{
System.out.println(i + " " +list.get(i));
}



}
}

niedziela, 21 czerwca 2015

very simple python port scanner

import socket
from socket import *
import sys


target = raw_input("Enter hostname: ")

addr = gethostbyname(target)
print("ip addres: ",addr)

for port in range(1,1000):
    s = socket(AF_INET,SOCK_STREAM)
    result = s.connect_ex((addr,port))
    if(result == 0):
        print("port %d: Open "%(port,))

find all active host in network

nmap -sP 192.168.0.1/24

poniedziałek, 15 czerwca 2015

create jar file from java class

manifest.txt
Main-Class: oop/contructorIntro

┌─[marek@lati]─[~/workspace/nauka_java/bin]
└──╼ ll
razem 24
drwxrwxr-x 2 marek marek 4096 cze 15 15:12 basic
drwxrwxr-x 2 marek marek 4096 cze 15 21:27 userIO
drwxrwxr-x 2 marek marek 4096 cze 15 23:22 jars
-rw-rw-r-- 1 marek marek   32 cze 15 23:25 manifest.txt
drwxrwxr-x 2 marek marek 4096 cze 15 23:25 oop
-rw-rw-r-- 1 marek marek 3719 cze 15 23:29 constr.jar

┌─[marek@lati]─[~/workspace/nauka_java/bin/oop]
└──╼ ll
razem 24
-rw-rw-r-- 1 marek marek 1045 cze 15 15:51 Test.class
-rw-rw-r-- 1 marek marek  513 cze 15 15:51 classIntro.class
-rw-rw-r-- 1 marek marek   32 cze 15 23:17 manifest.txt
-rw-rw-r-- 1 marek marek  868 cze 15 23:29 Person.class
-rw-rw-r-- 1 marek marek  605 cze 15 23:29 graph.class
-rw-rw-r-- 1 marek marek 1350 cze 15 23:29 contructorIntro.class



jar -cvfm constr.jar manifest.txt oop/*.class

czwartek, 11 czerwca 2015

wtorek, 12 maja 2015

all in one - class,method with param and loop :)

class Line
{
    public void line()
    {
        System.out.println("-----------");
    }
}
class loops
{
    public void goUp(int z)
    {
        for(int i=0;i<=z;i++)
        {
            System.out.println(i);
        }
    }
    public void goDown(int x)
    {
        for (int i=x; i>=0;i--)
        {
            System.out.println(i);
        }
    }
}
public class forLoop
{

    public static void main(String[] args)
    {
        loops loop = new loops();
        Line line = new Line();
       
        loop.goDown(10);
        line.line();
        loop.goUp(10);
    }
}

środa, 22 kwietnia 2015

let java choose my son name :) ArrayList test

package random;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import lib_package.separator;

public class randomChoose
{
private static Random random = new Random();

public static void main(String[] args)
{
List<String> imiona = new ArrayList<String>();
imiona.add("Wiktor");
imiona.add("Modest");
imiona.add("Marcel");
imiona.add("Mikołaj");
imiona.add("Ignacy");
imiona.add("Michał");
imiona.add("Stanisław");


for(int i=0;i<imiona.size();i++)
{
System.out.println(imiona.get(i));
}
separator.line();

int index = random.nextInt(imiona.size());
System.out.println(imiona.get(index));

separator.line();

int index1 = (int)(Math.random()*imiona.size());
System.out.println(imiona.get(index1));
}
}

środa, 8 kwietnia 2015

Simple inheritance example - Java

class Rodzina
{
String name="Marek";
public void print()
{
System.out.println("class Rodzina");
System.out.println(name);
}
}

class Osoba extends Rodzina
{
int age = 32;
public void print()
{
System.out.println("class Osoba");
System.out.println(age);
super.print();
}
}

public class dziedziczenie
{
public static void line()
{
System.out.println("--------");
}
public static void main(String[] args)
{
Osoba o = new Osoba();
o.print();
line();
Rodzina r = new Rodzina();
r.print();
}
}

piątek, 3 kwietnia 2015

get day - SimpleDateFormat Java

package dateANDtime;

import java.text.SimpleDateFormat;
import java.util.Date;

public class getDayFromDate
{
public static void main(String[] args)
{
Date now = new Date();

SimpleDateFormat sdf = new SimpleDateFormat("E");
String checkDay = sdf.format(now);

String x = checkDay.toString();
System.out.println(x);

if(checkDay.equals("Pt"))
{
System.out.println("piatek");
}
else if(checkDay.equals("Cz"))
{
System.out.println("czwartek");
}
else if(checkDay.equals("Śr"))
{
System.out.println("środa");
}
else if(checkDay.equals("Wt"))
{
System.out.println("wtorek");
}
else if(checkDay.equals("Pn"))
{
System.out.println("poniedzialek");
}
else
{
System.out.println("!!!!weekend!!!!");
}
}
}

czwartek, 2 kwietnia 2015

how to draw nice line separator in Java (def line python substitute)

public class test
{
public static void line(int leng)
{
for (int i=0;i<leng;i++)
{
System.out.print("-");
}
System.out.println();
}
public static void main(String[] args)
{
                 line(50);
}
}

it can be substitute of:

def line():
    print(50*"-")

środa, 1 kwietnia 2015

InputMismatchException -- exceptionBasics

import java.util.InputMismatchException;
import java.util.Scanner;


public class exceptionBasics
{
public static void main(String[] args)
{
int i = 0;
boolean done = false;
Scanner input = null;
do
{
try
{

input = new Scanner(System.in);
System.out.print("Enter an integer: ");
i = input.nextInt();

}
catch(InputMismatchException e)
{
System.out.println("you dont enter int!");
}


}
while (!done);
input.close();
System.out.printf("you entered: %d\n",i);

}
}

poniedziałek, 30 marca 2015

how to find all host in network

marek ~ $ nmap -sP 10.91.15.1/24

Starting Nmap 6.46 ( http://nmap.org ) at 2015-03-30 09:20 CEST

Nmap scan report for 10.91.15.1
Host is up (0.064s latency).

Nmap scan report for 10.91.15.2
Host is up (0.24s latency).

Nmap scan report for 10.91.15.3
Host is up (0.26s latency).

Nmap scan report for 10.91.15.59
Host is up (0.041s latency).

Nmap scan report for 10.91.15.61
Host is up (0.31s latency).

Nmap scan report for 10.91.15.234
Host is up (0.00045s latency).

Nmap done: 256 IP addresses (6 hosts up) scanned in 7.67 seconds

alternative:

for i in `nmap -sP 10.91.15.1/24 | grep 10. | awk '{print $5}'`; do ping -c1 $i;done

niedziela, 22 marca 2015

all necessary video codec for fedora

sudo yum install gstreamer gstreamer-ffmpeg gstreamer-plugins-bad gstreamer-plugins-bad-free gstreamer-plugins-bad-nonfree gstreamer-plugins-base gstreamer-plugins-good gstreamer-plugins-ugly gstreamer-plugin-crystalhd gstreamer1-plugins-bad-freeworld gstreamer1-plugins-bad-free gstreamer1-plugins-good gstreamer1-libav ffmpeg
Read more at http://dottech.org/128666/install-media-codecs-audio-video-fedora-guide/#jtu1E9wLSUc0ZGmb.99

sobota, 28 lutego 2015

String ArrayList - Java

package tablice;

import java.util.ArrayList;
import java.util.Scanner;

public class arrayListTest
{
public static void main(String[] args)
{
String in;
Scanner input = new Scanner(System.in);

ArrayList<String> array1 = new ArrayList<>();

array1.add("Marek");
array1.add("Gosia");
array1.add("Wiktor");
array1.add("Weronika");

System.out.println("before: "+array1.size());
while(true)
{
System.out.print("Enter arrayList element: ");
in = input.next();

if(!in.equals("q"))
{
array1.add(in);
}
else
{
System.out.println("the end");
break;
}
}
System.out.println("before: "+array1.size());
input.close();


}
}

sobota, 21 lutego 2015

arrays in C++

#include <iostream>
using namespace std;

void line()
{
cout << "+=+=+=+=+=+=" << endl;
}
int main()
{
int size;
int liczby[10];
liczby[0] = 100;
liczby[1] = 200;
liczby[2] = 300;
liczby[3] = 400;
liczby[4] = 500;
liczby[5] = 600;
liczby[6] = 700;
liczby[7] = 800;
liczby[8] = 900;
liczby[9] = 1000;
cout << liczby << endl;

for(int i=0;i<10;i++)
{
cout << liczby[i] << endl;
}
line();

size = sizeof liczby/sizeof(int);
cout << size << " elements";

}

sobota, 14 lutego 2015

Docker - install and run http server nginx

root ~ # docker run -d -p 80:80 nginx

Unable to find image 'nginx' locally
Pulling repository nginx
4b5657a3d162: Download complete
511136ea3c5a: Download complete
30d39e59ffe2: Download complete
c90d655b99b2: Download complete
d9ee0b8eeda7: Download complete
3225d58a895a: Download complete
224fea58b6cc: Download complete
ef9d79968cc6: Download complete
f22d05624ebc: Download complete
117696d1464e: Download complete
2ebe3e67fb76: Download complete
ad82b43d6595: Download complete
e90c322c3a1c: Download complete
23b07e3a31e0746c9b9b32f3a4cc0e377c6edef07db244e2a820bcbf407dc9fe


root ~ # docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                         NAMES
6ac5022624ca        nginx:latest        "nginx -g 'daemon of   12 seconds ago      Up 11 seconds       443/tcp, 0.0.0.0:80->80/tcp   lonely_thompson  



root ~ # docker logs 6ac5022624ca
172.17.42.1 - - [14/Feb/2015:21:39:46 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0" "-"
2015/02/14 21:39:46 [error] 6#0: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.42.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "0.0.0.0"
172.17.42.1 - - [14/Feb/2015:21:39:46 +0000] "GET /favicon.ico HTTP/1.1" 404 168 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0" "-"
2015/02/14 21:39:46 [error] 6#0: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.42.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "0.0.0.0"
172.17.42.1 - - [14/Feb/2015:21:39:46 +0000] "GET /favicon.ico HTTP/1.1" 404 168 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0" "-"

Docker - how to remove all container

root ~ # docker rm $(docker ps -aq)

ffcbe71e96ee
e14a617d1e7b

Docker - how i can back to docker container

List of existing instances

root ~ # docker attach 2179adde3d7f

2015/02/14 19:54:51 You cannot attach to a stopped container, start it first

root ~ # docker start 2179adde3d7f
2179adde3d7f

root ~ # docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
2179adde3d7f        ubuntu:latest       "/bin/bash"         About a minute ago   Up 2 seconds                            jolly_pare
        
root ~ # docker attach 2179adde3d7f

root@2179adde3d7f:/

Docker - first look how to


Docker

docker run ubuntu - run ubuntu instance

docker run ubuntu echo 'marek borkowski' - execute command on dockUbuntu instance

docker run -i -t ubuntu bash - run bash shell on dockUbuntu intance


list docker process

root ~ # docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED              STATUS                      PORTS               NAMES
6e199c080cf8        ubuntu:latest       "bash"                 About a minute ago   Exited (0) 59 seconds ago                       condescending_colden
c0c3e7dbee7b        ubuntu:latest       "echo 'marek borkows   2 minutes ago        Exited (0) 2 minutes ago                        loving_wozniak      
cb102d353c5a        ubuntu:latest       "/bin/bash"            2 minutes ago        Exited (0) 2 minutes ago



run something more on docker instance

start do something loop

root ~ # docker run -d ubuntu /bin/bash -c "while true; do echo hello world; date; sleep 1; done"
c8494d50aca84e12ac380c24bce4ff1dcd4254173be53568ccda68a236e9732e


root ~ # docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED              STATUS                          PORTS               NAMES
c8494d50aca8        ubuntu:latest       "/bin/bash -c 'while   6 seconds ago        Up 6 seconds                                        tender_mccarthy      


root ~ # docker logs c8494d50aca8
hello world
Sat Feb 14 17:59:26 UTC 2015
hello world
Sat Feb 14 17:59:27 UTC 2015
hello world
Sat Feb 14 17:59:28 UTC 2015
hello world
Sat Feb 14 17:59:29 UTC 2015
hello world
Sat Feb 14 17:59:30 UTC 2015
hello world
Sat Feb 14

stop instance

 root ~ # docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                      PORTS               NAMES
c8494d50aca8        ubuntu:latest       "/bin/bash -c 'while   11 minutes ago      Up 11 minutes                                   tender_mccarthy      

     
root ~ # docker stop c8494d50aca8

c8494d50aca8

root ~ # docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                           PORTS               NAMES
c8494d50aca8        ubuntu:latest       "/bin/bash -c 'while   12 minutes ago      Exited (-1) About a minute ago                       tender_mccarthy      


remove existing intance:

root ~ # docker ps -a

CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                       PORTS               NAMES
c8494d50aca8        ubuntu:latest       "/bin/bash -c 'while   22 minutes ago      Exited (-1) 11 minutes ago                       tender_mccarthy      
52b37c74ae04        ubuntu:latest       "/bin/bash -c 'while   24 minutes ago      Exited (1) 24 minutes ago                        suspicious_feynman  
6e199c080cf8        ubuntu:latest       "bash"                 30 minutes ago      Exited (0) 30 minutes ago                        condescending_colden
c0c3e7dbee7b        ubuntu:latest       "echo 'marek borkows   31 minutes ago      Exited (0) 31 minutes ago                        loving_wozniak      
cb102d353c5a        ubuntu:latest       "/bin/bash"            31 minutes ago      Exited (0) 31 minutes ago                        jolly_galileo        

root ~ # docker rm 52b37c74ae04
52b37c74ae04
root ~ # docker rm 6e199c080cf8
6e199c080cf8
root ~ # docker rm c0c3e7dbee7b
c0c3e7dbee7b
root ~ # docker rm cb102d353c5a
cb102d353c5a
root ~ #
root ~ #
root ~ # docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                       PORTS               NAMES
c8494d50aca8        ubuntu:latest       "/bin/bash -c 'while   23 minutes ago      Exited (-1) 11 minutes ago                       tender_mccarthy

sobota, 31 stycznia 2015

how to create temp file with Java

import java.io.File;
import java.io.IOException;

public class tempFile
{
public static void main(String[] args) throws IOException
{
File f = File.createTempFile("temp_", null);

System.out.println(f.getAbsolutePath());

f.deleteOnExit();

}
}

output:
/tmp/temp_538005290434749678.tmp
/tmp/temp_5224913897241434358.tmp


czwartek, 22 stycznia 2015

python loop - basic escape

a = True
print("Enter quit to quit")
while(a):
   
    string = raw_input("Enter your name: ")
    if(string == "quit"):
        a = False
print("the end")
   
   

czwartek, 15 stycznia 2015

very small python "game" thanks to Bucky

import random

class Enemy:
    life = 10
 
    def attack(self):
        print("aouch!")
        self.life -= 1
     
    def checkLife(self):
        if self.life <=0:
            print ("!!!!you are dead!!!!!")
        else:
            print (str(self.life)+ " life left")
         
alien = Enemy()
predator = Enemy()

x = random.randrange(1,11)
for i in range(x):
    alien.attack()
 
alien.checkLife()

środa, 14 stycznia 2015

Simple python class calc

class Kalkulator:
def __init__(self,x,y):
self.x = x
self.y = y

def addXY(self):
print("suma: ",(self.x + self.y))

def subXY(self):
print("roznica: ",(self.x - self.y))

def mulXY(self):
print("mnozenie: ",(self.x * self.y))

def divXY(self):
if (self.y == 0):
print "div by zero"
else:
print("dzielenie: ",(self.x / self.y))

def line():
print 50*"-"

def Main():
a = int(raw_input("enter a: "))
b = int(raw_input("enter b: "))
line()

p1 = Kalkulator(a,b)
p1.addXY()
p1.subXY()
p1.mulXY()
p1.divXY()


if __name__ == '__main__':
Main()

piątek, 2 stycznia 2015

Smoothy way to open file in Java (with exception)

package Pliki;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


public class ReadFile
{
public static void main(String[] args)
{
try(BufferedReader reader = new BufferedReader(new FileReader("/etc/passwd")))
{
while (true)
{
String line = reader.readLine();
if(line == null)
{
break;
}
System.out.println(line);
}
reader.close();
}
catch (FileNotFoundException e)
{
System.err.println("There is no such file");
}
catch (IOException e)
{
System.err.println("IOExceptions");
}


}
}

czwartek, 1 stycznia 2015

escape from Loop java

package loops;

import java.util.Scanner;

public class runFromLoop
{
static void line()
{
System.out.println("=-=-=-=-=-=-=-=-=-=-=");
}
public static void main(String[] args)
{
String name;
Scanner input = new Scanner(System.in);
StringBuffer buffer = new StringBuffer();

System.out.println("Enter quit to exit");
line();
while(true)
{
System.out.print("Enter something: ");
name=input.nextLine();

if (name.equals("quit"))
{
System.out.println("quit");
break;
}
else
{
buffer.append(name + "\n");
}
}
line();
System.out.print(buffer);

input.close();

}
}