10 Mayıs 2022 Salı

bash kodlama - declare built-in komutu

-a seçeneği
Array veya Associative Array tanımlanır

-n seçeneği
name reference içindir. bash 4.3 ile geliyor.

Örnek
Şöyle yaparız
#!/bin/bash

declare -A num word

word=(
 [a]='index_a'
 [b]='index_b'
 [c]='index_c'
)

num=(
 [a]=1
 [b]=2
 [c]=3
)

declare -n var="$1"

printf '%s\n' "${var[@]}"
Çağırmak için şöyle yaparız
bash  array_call_self.sh  word



9 Mayıs 2022 Pazartesi

systemd Nedir

Giriş
Açıklaması şöyle
Systemd is actually a fairly recent project, having been started in ~2010. Many others have been used before it: sysvinit, upstart, init-ng, s6, launchd (I think it had a Linux version once). Several Linux distributions still do not use systemd for various reasons.

Out of all those, systemd is the closest one that you even could call a "process manager". Linux doesn't actually rely on a process manager at all; any process can directly make (fork) a new child process whenever it decides to, uncontrolled. (Indeed so uncontrolled that when systemd started codifying things like "logging out should kill your leftover processes", wars were fought over it.)

The real primary job of systemd and other such programs is only to be a service manager: to automatically start certain specific processes, such as the daemon responsible for displaying the login screen (GDM, agetty) and – sometimes – to restart them when they crash. But once you get to the login screen, everything else can happen without the involvement of systemd/init.

Indeed with sysvinit, the actual init process did incredibly little: about the only service it oversaw was agetty. Literally everything else was done through ordinary shell scripts that never touched init proper. The command to start a service? Shell script. The whole initial boot process? Shell script that runs more shell scripts.
Açıklaması şöyle
At a high level, Systemd typically serves several functions:
  • Init system: Performs boot-time system initialization (e.g. creates or cleans temp files, etc.)
  • Run services at boot (e.g. cron, sshd, mariadb, etc.)
  • PID 1 process: The master process under which all other processes live
  • Process supervisor (a.k.a. process manager): Starts, monitors, restarts additional services
  • Additional services (Systemd does a lot, e.g. logging, mounts, and much more)

Most of these functions can be handled separately, but Systemd "does it all".

3 Mayıs 2022 Salı

Synaptic Package Manager

Giriş
Altta apt komutunu kullanan eski Package Manager. Kurulumu burada

6 Nisan 2022 Çarşamba

Pluggable Authentication Modules (PAM)

Giriş
PAM'e bir sürü module takılabilir. Örneğin
- pam_unix
- pam_ldap

passwd komutu yazısında bazı örnekler var
Ayrıca Ubuntuda getty de giriş için PAM'i kullanır


pam_unix
pam_unix'in açıklaması şöyle. /etc/passwd dosyası artık kullanılmadığına göre, /etc/shadow dosyasındaki şifreye göre şifreyi kontrol eder
NAME
   pam_unix - Module for traditional password authentication

SYNOPSIS
   pam_unix.so [...]

DESCRIPTION
   This is the standard Unix authentication module. It uses standard calls
   from the system's libraries to retrieve and set account information as
   well as authentication. Usually this is obtained from the /etc/passwd
   and the /etc/shadow file as well if shadow is enabled.
nullok alanı
Açıklaması şöyle. /etc/shadow dosyasında şire alanı boş ise şifre sormadan giriş yapılabilir
nullok
The default action of this module is to not permit the user access to a service if their official password is blank. The nullok argument overrides this default.

(if it's enabled, and the password is empty, the module doesn't even ask for the password but accepts the login directly.)


getty - Ubuntu İçin Login

Giriş
Açıklaması şöyle
First, you don't log in to a shell, you log in to a (virtual) terminal.
  • a getty program opens a tty port, prompts for a login name and invokes a login program (/bin/login by default - although Linux's agetty may be configured to use a non-standard login program)

  • the login program performs authentication and session setup, including initializing the environment and invoking the user's login shell.
In current Ubuntu systems, getty is managed as a systemd service (ex. getty@tty1.service for the virtual terminal tty1), and login uses the Pluggable Authentication Modules (PAM) subsystem for authentication - in particular, the pam_unix module is "for traditional password authentication".


31 Mart 2022 Perşembe

find komutu permission'a göre arama seçenekleri

Giriş
Açıklaması şöyle
Using -perm, we can find all files with a particular permission combination.
Örnek
Şöyle yaparız.
find ./test -perm 0755
Örnek
Group permission olmayan dosyaları bulmak için şöyle yaparız.
find . \! -perm /g+rwx

find komutu last accessed/modified time'a göre arama seçenekleri

Giriş
Açıklaması şöyle. a ile başlayanlar accessed, c ile başlayanlar changed, m ile başlayanlar modified içindir
Here are all the options for checking access/modify time:

-amin n - the file was last accessed within n minutes ago.
-atime n - the file was last accessed within n days ago.
-cmin n - the file status changed within n minutes ago.
-ctime n - the file status changed within n days ago.
-mmin n - the file was last modified within n minutes ago.
-mtime n - the file was last modified within n days ago.
-anewer file - the searched file was modified more recently than [FILE]. If using -L or -H, and [FILE] is a symbolic link, then the file it points to is used.
-cnewer file - the search for file status changed more recently than [FILE]. If using -L or -H, and [FILE] is a symbolic link, then the file it points to is used. If you add -daystart to the end of any of these, the measurement will be taken from the start of the current day, rather than the current time, 
Burada şu açıklama önemli
Finally, + and - modifications are also available. For instance, -amin -5 will find anything modified in the last 5 minutes, but -amin +5 will find anything modified more than 5 minutes ago.

Modified Seçenekleri
-mmin seçeneği
Son x dakika değiştirmiş dosyaları listeler. Açıklaması şöyle.
-mmin on the other hand can count in minutes. So, if strict accuracy is vital, then -mmin +1440 ( 1440 minutes = 1 day ) could be used instead of -mtime +1
Örnek
Gün başından en fazla 5 dakika önce değiştirilmiş dosyaları bulmak için şöyle yaparız
find . -name "*.txt" -mmin 5 -daystart
-mtime seçeneği
Son x günde değiştirilmiş dosyaları listeler. Birim olarak gün kullandığı için 1.5 gün diye bir şey bilmez. Ya 1 gün ya 2 gün, ya da 3 gün şeklindedir. Açıklaması şöyle
In other words, -mtime can count only in units of 24 hours or one day each so as far as -mtime +1 goes, this means exactly more than one day by at least one day ( ie. two days+ )
Örnek
Şöyle yaparız. Son 6 günden eski dosyaları silmek için şöyle yaparız.
find "$DESDIR" -mtime +6 -type f -delete