Categories
Linux

Linux Process basics

List of processes

systemctl list-unit-files | grep enabled
ps aux | less

Top memory consuming process

ps aux --sort -rss | head -11
ps aux --sort +rss | tail -10
ps aux | sort -nrk 3,3 | head -n 5

Top Process ID’s

ps -eo pmem,pcpu,vsize,pid | sort -k 1 -nr | head -5
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

Watch processes

top
watch "ps aux | sort -nrk 3,3 | head -n 5"

CPU info

cat /proc/cpuinfo 

Number of CPU’s

cat /proc/cpuinfo | wc -l
Categories
Command Line

Basic Linux Dig commands

# dig google.com
# dig google.com +short

MX Record

# dig google.com MX

SOA Record for Domain

# dig google.com SOA

TTL

# dig google.com TTL

Get only Answers

# dig google.com +nocomments +noquestion +noauthority +noadditional +nostats

Get all DNS Records Types

# dig google.com ANY +noall +answer

DNS Reverse Look-up

dig -x 216.58.206.110 +short

Multiple DNS Records

# dig yahoo.com mx +noall +answer redhat.com ns +noall +answer

Create $HOME/.digrc to configure

Categories
Python

Conda Python Environments

1. Creating Environments

conda create --name py2 python=2.7
conda create --name py3 python=3.7

2. Switch to Python 2

source activate py2

Deactivate Conda Python 2

source deactivate

3. Switch to Python 3

source activate py3

Deactivate Conda Python 3

source deactivate
Categories
Command Line

Useful Linux CLI commands

hostname -I
[root@ftp ~]# groups
[root@ftp ~]# groups root
[root@ftp ~]# grep root /etc/group

Symbolic Links

Hard Link

ln /path/to/file /path/to/hardlink

Soft Link

ln -s /path/to/file /path/to/link

To Prevent Soft Link Overwrite

ln -s -b /path/to/file /path/to/link

List all symbolic links

ls -lt

Unlink a file

unlink linkfile
grep -r SSLCertificateFile /etc/httpd
httpd -S
openssl x509 -in server.crt -noout -subject

All users:

$ getent passwd

All groups:

$ getent group

All groups with a specific user:

$ getent group | grep user

Delete user

userdel user's username

Delete including users home directory

userdel -r user's username

Categories
Python Web Server

Run shell script in Apache Airflow

Create the script.py inside the ../airflow/dags folder

from builtins import range
from datetime import timedelta

import airflow
from airflow.models import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.operators.dummy_operator import DummyOperator

args = {
    'owner': 'airflow',
    'start_date': airflow.utils.dates.days_ago(2),
}

dag = DAG(
    dag_id='dagid1',
    default_args=args,
    schedule_interval='0 0 * * *',
    dagrun_timeout=timedelta(minutes=60),
)

# [START howto_operator_bash]
create_command = """
echo 'Hello world';
echo 'Welcome';"""

run_this = BashOperator(
    task_id='taskid1',
    bash_command=create_command,
    dag=dag,
)