linux/

Monitor number of open sockets by a process

Example with watch command:

watch -n 1 'ps aux | kazy -i cmproxy -e kazy | kazy -r "[\d]+" -x | xargs -I % ls -l /proc/%/fd/ | kazy -i socket | wc -l'

Example with ttyplot command:

{ while true; do ps aux | kazy -i cmproxy -e kazy | kazy -r "[\d]+" -x | xargs -I % ls -l /proc/%/fd/ | kazy -i socket | wc -l; sleep 1; done } | ttyplot
| 16 Apr 2023

Monitor DNS query time

{ while true; do dig google.com | kazy -i "Query time" | kazy -r -x "[\d.]*"; sleep 1; done } | ttyplot -t "dig to google.com"
| 12 Apr 2023

Plot real time ping data in terminal

Install ttyplot:

grm install tenox7/ttyplot -n ttyplot

Ping plot:

ping 8.8.8.8 | sed -u 's/^.*time=//g; s/ ms//g' | ttyplot -t "ping to 8.8.8.8" -u ms

More examples

| 12 Apr 2023

Monitor all http traffic in wireshark on specific ports

Open wireshark GUI as root user:

sudo wireshark

Start capturing by clicking Capture button and add the following display filter:

http and (tcp.port == 8082 or tcp.port == 8000)
| 29 Mar 2023

git: How to remove submodule pointer update in pull request

Case 1: it is done in a separate commit:

  • rebase on a base branch git rebase -i <base_branch>
  • in the editor, find the commit which updates the pointer and remove it from history (by replacing pick with d)
  • force push it when the rebase is done

Case 2: it is done in the commit which contains other changes

  • rebase on a base branch git rebase -i <base_branch>
  • in the editor, find the commit which includes the pointer update and mark it for editing (by replacing pick with e)
  • git will start rebasing the code and will stop on selected commit for editing
  • unstage the change git restore --staged <path_to_submodule>
  • continue the rebase git rebase --continue
  • force push it when the rebase is done
| 29 Mar 2023

Make port available as unix socket

socat UNIX-LISTEN:/var/run/hapee-lb.sock,mode=666,fork TCP-CONNECT:127.0.0.1:1936

Will create /var/run/hapee-lb.sock file which forwards all input to 127.0.0.1:1936. fork parameter will allow it to handle connection close and accept more than 1 request

| 13 Feb 2023

git: Cherry-pick branch

Very useful command to cherry pick the whole branch

git cherry-pick 751a77^..8b62f1

^ - means the the first commit will be included too

| 3 Nov 2022

Use Github Desktop with pre-commit hooks with husky

If your repository has an installed pre-commit hook which uses husky or anything similar and you use Github Desktop for linux installed via flatpak it won’t work. The reason for this is that flatpak environment doesn’t have all necessary dependencies (npx, husky and etc.). There is a way to mount parts of your host file system to the flatpak environment (with --filesystem flag), but it excludes all sensitive folders (including /usr/bin/). A possible solution would be to mount the content of /usr/bin/ to a custom folder in flatpak environment and override PATH environmental variable. But the quick fix for now is to just disable it:

flatpak override --user --env=HUSKY=0 io.github.shiftey.Desktop
| 5 Sep 2022

Migrate from Rocky Linux to CentOS Stream

There is no official guide to migrate from Rocky Linux to CentOS Stream, however, it can be achieved by using official CentOS to CentOS Stream migration guide

  1. Install centos-release-stream package
dnf install https://vault.centos.org/centos/8/extras/x86_64/os/Packages/centos-release-stream-8.1-1.1911.0.7.el8.x86_64.rpm
  1. The next step is to swap Rocky Linux repositories to CentOS Stream ones. This is done with dnf swap centos-{linux,stream}-repos -y command. However, this command will cause multiple conflicts in Rocky Linux. To solve them:
  • copy /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial file from any Centos Stream system into Rocky Linux
  • remove conflicting packages:
    rpm -e --nodeps rocky-repos
    rpm -e --nodeps rocky-release
    
  • complete installing CentOS Stream repositories
    dnf swap centos-{linux,stream}-repos -y
    
  1. Switch to CentOS Stream
dnf distro-sync -y
  1. Verify installation and reboot the server:
cat /etc/centos-release
reboot
| 13 Jul 2022

Block IP address in firewalld

sudo firewall-cmd --add-rich-rule="rule family='ipv4' source address='89.20.160.77' reject" --timeout=1h

Valid values for timeout - numbers followed by s, m or h

Documentation

| 23 May 2022