11 Kasım 2021 Perşembe

xinput komutu

Giriş
Farenin düğmesi tıklanınca başka bir düğme tıklanmış gibi yapmak veya etkinsizleştirmek için kullanılabilir.

set-button-map seçeneği
Örnek
Şöyle yaparız
Identify the ID/IDs of your device with

 xinput list 
Get the button map with

 xinput get-button-map <ID>
Set the button action

 xinput set-button-map <ID> 1 <new action>

Repeat the last command for as many IDs as your mouse has. 1 stands for the mapping of left-click, then for middle click, etc. Use for <new action> number 0 to disable middle-click, number 1 if you want to make it equivalent to left-click, etc.

10 Kasım 2021 Çarşamba

~/.ssh/known_hosts Dosyası

Giriş
İlk defa bağlantı kurulan bir ssh sunucusunun fingerprint (parmak izi) değeri bu dosyaya yazılır. Dosyanın içi şöyledir
myhost,1.2.3.4 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYT...YjdB=
Aynı sunucu için birden fazla satır olabilir ancak bu tavsiye edilmiyor. Açıklaması şöyle
It is permissible (but not recommended) to have several lines or different host keys for the same names.
Hashed Format
Dosyanın içindeki satırlar hashed formatta olabilir veya olmayabilir. Bu ayar ~/.ssh/config dosyasından kontrol ediliyor

7 Kasım 2021 Pazar

Kubernetes ConfigMap - Gizli Olmayan Veri

Giriş
ConfigMap içinde non-confidential yani gizli olmayan veri saklanır. Eğer gizli veri (password, token, key gibi) saklanacaksa Secret kullanılır

Pod içinde kullanırken
envFrom başlığı altında configMapRef şeklinde kullanılır
envFrom başlığı altında secretRef şeklinde kullanılır

Örnek
Şöyle yaparız
apiVersion: v1
kind: Pod
metadata:
  name: static-web
  labels:
    role: myrole
spec:
  containers:
  - name: nginx
    image: nginx
    envFrom:
    - configMapRef:
        name: testconfigmap
ConfigMap yaratmak
ConfigMap yaratmak için 2 tane yöntem var
1. ConfigMap yaml dosyası tanımlanır
2. Komut satırında "kubectl create configmap ..." yapılır

1. Dosya Tanımlama
kind olarak ConfigMap verilir ve data bölümünde key-value değerleri tanımlanır

Örnek
Şöyle yaparız
apiVersion: v1
kind: ConfigMap
metadata:
  name: mongodb
data:
  database-name: microservices
Örnek
Şöyle yaparız
apiVersion: v1
kind: ConfigMap
metadata:
  name: geared-marsupi-configmap
data:
  myvalue: "Hello World"
  drink: coffee
2. Komut Satırı
Örnek
configmap yaratmak için şöyle yaparız
#Create ConfigMap
kubectl create configmap testconfigmap --from-literal=TestKey1=TestValue1 
--from-literal=TestKey2=TestValue2 kubectl create configmap testconfigmap --from-file=/opt/test_file #Test kubectl get configmaps kubectl describe configmaps kubectl describe configmap testconfigmap
komut satırından kullanmak istersek iki seçenek var. Açıklaması şöyle
1. Use the contents of an entire directory with kubectl create configmap my-config --from-file=./my/dir/path/
2. Use the contents of a file or specific set of files with kubectl create configmap my-config --from-file=./my/file.txt

4 Kasım 2021 Perşembe

grep General Output Control - Dosya İsimleri veya Çıktıyı Kontrol Eder

Giriş
Çıktıyı kontrol etmek içindir.
--color
Açıklaması şöyle.
Surround the matched (non-empty) strings, matching lines, context lines, file names, line numbers, byte offsets, and separators (for fields and groups of context lines) with escape sequences to display them in color on the terminal.  ...  WHEN is neveralways or auto.
Varsayılan değer auto olduğu için şöyle yaparız.
grep --color ...
-L,--files-without-match
Açıklaması şöyle. Eşleşmeyen dosyaları verir
-L, --files-without-match

Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.

-l, --files-with-matches

Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match.
Örnek
Şöyle yaparız. Önce 'cat' kelimesini içeren dosyaların isimlerini alırız. Daha sonra bu dosyalarda 'dog' kelimesi içermeyenleri buluruz.
grep -L 'dog' $(grep -l 'cat' <list of files>)
-l,--files-with-matches
Açıklaması şöyle
grep -l lists the names of files with matching strings
Örnek
Şöyle yaparız. Bulunduğum dizin ve altındaki her şeyi tarar içinde abc geçen dosyaları listeler
grep -lRe abc .
-q, --quite, --silent
quite anlamına gelir. stdout'a çıktı yazmaz. If koşullarında kullanılır. Şöyle yaparız
if grep -q 'release 7\.[56] ' /etc/redhat-release
then ...
-o
Genellikle düzenli ifadeler ile kullanılır. Sadece eşleşen kısım gösterilir. Açıklaması şöyle
-o, --only-matching
Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.
Burada non-empty kısmı önemli çünkü bazen düzenli ifadeler ile boş string çıktısı gelebiliyor. Açıklaması şöyle
Many regular expressions can match empty text; for example:$ grep -E '.?' <<<""

outputs a blank line because the empty line matches. However, adding -o results in no output at all:$ grep -Eo '.?' <<<""

because -o ignores empty matches.

Specifying that -o ignores empty matches means the implementers don’t need to decide what to do with zero-length matches, which would otherwise produce rather lengthy (and useless) output in many circumstances.
Örnek
Şöyle yaparız.
$ str='25 results [22 valid, 2 invalid, 1 undefined]'
grep -E -o '[0-9]+' <<<"$str"

3 Kasım 2021 Çarşamba

chmod komutu ve Kullanılabilecek Gruplar

Giriş
Gruplar şöyledir.
u, for the owner
g, for the group
o, for others
a, for all, which can also be written as ugo.
chmod komutunu kullanırken komutun hangi gruplara uygulanacağını belirtebiliriz. Eğer belirtmezsek sanırım umask ayarımız devreye giriyor

Kullanım şöyle
chmod grouplar (+ veya eksi veya = karakteri başlayan permission) (dosya ismi)
Permission için açıklama şöyle
  • If we want to give permissions to a set of users or user, we write +, so +x will give execute permission and +rx will give read and execute permission.
  • If we want to revoke permissions, we write -, so -rwx takes away read, write, and execute access.
  • If we want to replace permissions entirely, we use =, so =r will give read access, but remove execute and write if they existed. Similarly, =rw is the same as read and write access, with execute removed if it existed.
Örnek - u
Şöyle yaparız
chmod u+r file.txt
Örnek - u
Şöyle yaparız. ugo yerine all da kullanılabilir.
chmod ugo+rw file.txt
Örnek - u
Şöyle yaparız. user'a rwx verir geri kalan hakları kaldırır. group'a rw verir geri kalan hakları kaldırır. owner'a r verir geri kalan hakları kaldırır
chmod u=rwx,g=rw,o=r file.txt

Örnek - a Yani All Anlamına Gelir
Şöyle yaparız
To set all the bits, ignoring umask, you need to specify who you want to set them for:

chmod a+rwx file

or more explicitly,

chmod ugo+rwx file
Örnek - Gruplar İçin Ayrı Ayrı
755'i vermek için harfleri kullanarak şöyle yaparız
chmod -R u=rwx,g=rx,o=rx folder
Örnek - MyGroup ve Owner
secret dizinindeki group ve owner için hakları almak için şöyle yaparız
chmod -R g=,o= secret

31 Ekim 2021 Pazar

Kubernetes Container Lifecycle Events

Lifecycle Hook
İki tane lifecycle hook var. Açıklaması şöyle
PostStart: This hook is executed right after a container is created. However, the hook might be invoked after the container's ENTRYPOINT is executed. The hook handler must not accept any parameters.

PreStop: This hook is executed immediately before a container is terminated due to any reason, such as resource contention, liveness probe failure, etc. You cannot pass any parameters to the handler, and the container will be terminated irrespective of the outcome of the handler.
Lifecycle Hook Handlers
Hook'a iki çeşit handler takabiliriz. Açıklaması şöyle
There are two types of handlers that you can attach to a lifecycle hook:

exec: It executes the specified command in the container's main process. The command is executed in parallel with the container's ENTRYPOINT instruction. If the hook takes too long or fails, the kubelet process will restart the container.

httpGet or tcpSocket: It sends an HTTP request or establishes a TCP socket connection against a specific endpoint on the container. Unlike the exec, which is executed by the container, this handler is executed by the kubelet process.
Örnek - postStart
Şöyle yaparız
apiVersion: v1
kind: Pod
metadata:
  name: sidecar-container-demo
spec:
  containers:
    - image: busybox
      command: ["/bin/sh"]
      args:
        [
          "-c",
          "while true; do echo echo $(date -u) 'Written by busybox sidecar container' >> /var/log/index.html; sleep 5;done",
        ]
      name: sidecar-container
      resources: {}
      volumeMounts:
        - name: var-logs
          mountPath: /var/log
      lifecycle:
        postStart:
          httpGet:
            path: /index.html
            port: 80
            host: localhost
            scheme: HTTP
    - image: nginx
      name: main-container
      resources: {}
      ports:
        - containerPort: 80
      volumeMounts:
        - name: var-logs
          mountPath: /usr/share/nginx/html
  dnsPolicy: Default
  volumes:
    - name: var-logs
      emptyDir: {}
Örnek - preStop
Şöyle yaparız
apiVersion: v1
kind: Pod
metadata:
  name: prestop-demo
spec:
  containers:
    - image: nginx
      name: nginx-container
      resources: {}
      ports:
        - containerPort: 80
      lifecycle:
        preStop:
          exec:
            command:
              - sh
              - -c
              - echo "Stopping container now...">/proc/1/fd/1 && nginx -s stop
  dnsPolicy: Default

30 Ekim 2021 Cumartesi

bash yönlendirme - redirection - Standard Output, Standard Error Birleştirme

Standard Output,  Standard Error Birleştirme Nedir
Açıklaması şöyle. Bu komut aslında bayağı karışık bir hal alabiliyor.
When you redirect something to &number, you are not opening a new file at all; you're reusing an already open file along with whatever mode it was opened.

The numbers refer to "open file" handles (file descriptors). So there is no technical difference between how >& and >>& (and indeed <&) would work – they all just mean "clone the existing file descriptor using dup()".

That is, 2>&1 indicates that file descriptor #1 (which you previously opened for appending using >>logfile) is cloned into number #2. And yes, 2<&1 works identically.
Bu yönlendirme POSIX uyumlu. Açıklaması şöyle.
So >out.txt 2>&1 is a POSIX-compliant way to redirect both standard output and standard error to out.txt.
Örnek
&>
veya
>&
şeklinde kullanılabilir. İlk kullanım tercih edilmeli. Şu kullanım ile aynıdır
>word 2>&1
1 - stdout
2 - stderr
akımlarıdır.

Bash'e özel
Bash'e özel şöyle yaparız
my_command_here arg1 arg2 |& less
Açıklaması şöyle
Note that |& is a Bashism. It does not work with /bin/sh (normally). If you want this in a portable shell script, use 2>&1 and a normal pipe instead.


Kullanım Örneleri
Klasik kullanımı daha kolay anlamak için birleştirme işlemlerini soldan başlayarak okumak lazım

Örnek
Klasik kullanım için şöyle yaparız. out.txt yeniden yaratılır ve hem stderr hem de stdout out.txt dosyasına yönlendirilir. Burada stderr çıktısı stdout'a yönlendiriliyor
my command > out.txt 2>&1  
Örnek - dev/null
Klasik kullanım için şöyle yaparız. Örnekte ise hem stdout hem de stderr /dev/null'a gönderiliyor. Böylece tüm çıktı /dev/null'a gönderilir. 
my command > /dev/null 2>&1  
Windows'ta /dev/null yerine sadece nul kullanılır.
your_dos_command 2> nul
Örnek - Biraz Karışık
Bu karışık kullanım C veya C++ dillerindeki pointer işlemlerine benziyor.  Eğer şöyle yaparsak, soldan okumaya başlarsak stderr önce stdout'a yönlendirilir, daha sonra stdout /dev/null'a gönderilir. Ancak stderr'i değiştirmedik. Yani halen stderr çıktısını ekranda görürüz.
command 2>&1 1>/dev/null
Benzer bir örnek şöyle
$ ( echo "this is stdout"; echo "this is stderr" >&2 ) 1>foo 2>&1 1>bar
$ cat foo
this is stderr
$ cat bar
this is stdout
Açıklaması şöyle
We can see that 2>&1 sends stderr to the "foo" file that stdout was redirected to, but when we redirect stdout to "bar" we don't alter stderr's destination. 

Örnek
Yönlendirmeyi kaldırmak için şöyle yaparız
exec 3>&-
Örnek
Şöyle yaparız. Burada stdout açıkça out.txt dosyasına yönlendiriliyor. stderr ise stdout'a yönlendiriliyor. Yani her şey out.txt dosyasına yazılıyor
my command 1 > out.txt 2>&1  
Örnek
Aynı şeyi şöyle yaparız.
my command &> out.txt
Örnek
Aynı şeyi şöyle yaparız.
my command 1>>out.txt 2>>out.txt
Örnek
Sadece bazı komutların çıktısını stdout'a diğerlerini /dev/null'a yönlendirmek için şöyle yaparız. exec bir bash built-in komutu
exec 3>&1 &>/dev/null
some_command
another_command
command_you_want_to_see >&3
command3
Açıklaması şöyle
You can use the exec command to redirect everything for the rest of the script.

You can use 3>&1 to save the old stdout stream on FD 3, so you can redirect output to that if you want to see the output.