linux

Posts tagged with #linux
Total: 12

Finding PID Everywhere

the proc virtual filesystem

Notes | 2025-09-19 (updated 2025-10-25) | 1 min read
#container #linux #sysadmin

Usually at least one of those is present on any system

But sometimes the usual suspects are not available, especially in minimal containers.

But there is another, more low level, way that works: /proc

This is a virtual filesystem provided by the kernel about running processes.

So to mirror something like this:

$ ps aux |grep sleep
    5 root      0:00 sleep 1000
   21 root      0:00 sleep 10000000
   36 root      0:00 grep sleep

We could do:

Read more…

Cleanup After Script Exit

Notes | 2024-09-03 (updated 2025-10-25) | 1 min read
#bash #linux #scripting

Many of my scripts work with temporary files, usually relative to the scripts directory1, while at the same time using set -e to exit as soon as something fails.

In this scenario the script leaves behind these temporary files by default, which is not desirable.

We can however do a proper cleanup using the trap concept.

Read more…

HaProxy: Think About DNS Resolution

Notes | 2024-06-04 (updated 2025-10-25) | 1 min read
#haproxy #linux #sysadmin

By default HAProxy resolves all DNS names in it’s config on startup and then never again.

This might cause issues down the road if DNS records, for example the ones for backends, change.

This section of the documentation is a good starting point as it describes IP address resolution using DNS in HAProy really well: https://docs.haproxy.org/3.0/configuration.html#5.3

Additionally this guide can also be helpful: https://www.haproxy.com/documentation/haproxy-configuration-tutorials/dns-resolution/

Working With Dates in Bash and Other Shells

Notes | 2024-02-22 (updated 2025-10-25) | 1 min read
#bash #linux #scripting

Often times we need the current date (and time) when scripting inside bash or other shells. For example when creating a backup file or writing to a log.

Read more…

Navigate to Script Directory

Notes | 2024-01-28 (updated 2025-10-25) | 1 min read
#bash #linux #scripting

Often times when writing scripts I want to reference files in the same directory, but keep the script portable in case it is part of a git repository being checked out somewhere else or just the folder getting moved.

Read more…

CLI fuzzy search

Notes | 2023-10-08 (updated 2025-10-25) | 1 min read
#linux #productivity #search #slashpage-uses

I often whish to search through large bodies of text, like my knowledge base or source code repositories, from the command line.

I use fuz for this and I’m quite happy with it.

I also have it aliased to my knowledge base folder for even easier searching.

alias search="fuz -p /path/to/knowledge-base/"

WSL2 & Keychain

Notes | 2022-12-08 (updated 2025-10-25) | 1 min read
#linux #ssh #wsl

The problem

If you use ssh-agent with an encrypted ssh key it does not persist when you open a new terminal window.

The solution

Use keychain instead.

  1. Install
    sudo apt install keychain
    
  2. Add to your shells rc file, eg. .bashrc or .zshrc
    # Repeat this line for all keys you want to unlock and use this way
    /usr/bin/keychain -q --nogui $HOME/.ssh/id_rsa
    source $HOME/.keychain/wsl-sh
    
  3. Unlock your keys on shell startup and enjoy

Resolve .local Through Nameserver With Netplan

Notes | 2021-08-13 (updated 2025-10-25) | 1 min read
#dns #linux #netplan #sysadmin

When using netplan it is easy to force .local DNS requests to go to you nameservers instead of being only resolved locally (the default and standard).

This also works with all other strange .WHATEVER domains you may have lying around in your organization.

Snippet from netplan configuration:

 nameservers:
        addresses:
          - X
          - Y
        search:
          - local
          - myotherstupiddomain

MongoDB Logrotate

Notes | 2021-08-12 (updated 2025-10-25) | 2 min read
#ansible #linux #logs #mongodb

MongoDB does not rotate it’s log on it’s own.

To get it to ratet we will use logrotate.

First, we need to configure some things in mongod.conf to get the desired behaviour when we utilize logrotate.

systemLog:
 destination: file
 path: /var/log/mongodb/mongod.log
 logAppend: true
 logRotate: reopen

Afterwards, we can create a logroatet configuration going in /etc/logrotate.d/mongodb.

/var/log/mongodb/mongod.log
{
 rotate 5 # Keep the last 5 rotated logs, so 6 files including the currently active
 size 10M # Rotate once the log reaches 10MB in size, depending on your envrionment you could instead use daily, weekly, monthly, etc
 missingok # It's ok if the log file does not exist
 create 0600 mongodb mongodb # Permissions and ownership for the roatetd logs
 delaycompress # Don't compress on first rotation, so we have the current log and log.1 uncompressed
 compress  # Compress everything else
 sharedscripts # Run this script only once and not for every matching file
 postrotate # Script to run after rotating
 /bin/kill -SIGUSR1 $(systemctl show --property MainPID --value mongod.service)
 endscript # End of script
}

The postrotate script simply finds the PID of mongod.service: systemctl show --property MainPID --value mongod.service and sends it a SIGUSR1 which is the signal MongoDB expects if you wish to rotate the log.

Read more…

Show all active user cron jobs on a system

Notes | 2021-08-11 (updated 2025-10-25) | 1 min read
#cron #linux #sysadmin

Debian/Ubuntu

grep -vH "#" /var/spool/cron/crontabs/*

RedHat/Centos/Rocky

grep -vH "#" /var/spool/cron/*