notes/technology/linux
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
- top
- htop / another top variant
- ps
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…
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 directory,
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…
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…
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…
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
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/*
Notes
| 2021-08-10
(updated 2025-10-25)
| 1 min read
#container
#dns
#linux
#sysadmin
Usually at least one of those is present on any system
But sometimes the usual suspects don’t work, especially in container-land.
After trying them you may try some more involved/unknown things:
getent
Part of glibc, this will probably work on nearly every system.
Or, if you specifically want to query A or AAAA records.
getent ahostsv4 example.org
getent ahostsv6 example.org
Using Python2 Or Python3
Given this depends on glibc it is more of a alternative then another real solution.
Read more…
Notes
| 2021-08-08
(updated 2025-10-25)
| 1 min read
#ansible
#automation
#linux
#security
#selinux
#sysadmin
#vmware
SELinux by default prohibits certain things from working through VMware tools (Ansible connection or plain API).
This can be solved two ways:
- Disabling SELinux: BAD, but easy
- Writing a custom SELinux policy: complicated but more secure
Note: Adding/Changing this policy through a VMware tools connection is thankfully possible
Example policy
This policy is the base for a VMware tools policy and allows entering the rpm context (yum).
module custom-vmtools 1.0;
require {
type rpm_script_t;
type vmtools_unconfined_t;
class process transition;
}
#============= vmtools_unconfined_t ==============
allow vmtools_unconfined_t rpm_script_t:process transition
Notes
| 2021-08-07
(updated 2025-10-25)
| 1 min read
#bash
#macos
date on MacOS does not support --date, so a workaround is needed.
Converting Date to unix epoch, adding one day in epoch and converting back.
The Scripty Way
Taken from a blog post
#!/bin/zsh
start=$year-01-01
end=$year-12-31
currentDateTs=$(date -j -f "%Y-%m-%d" $start "+%s")
endDateTs=$(date -j -f "%Y-%m-%d" $end "+%s")
offset=86400
while [ "$currentDateTs" -le "$endDateTs" ]
do
date=$(date -j -f "%s" $currentDateTs "+%Y-%m-%d")
echo $date
currentDateTs=$(($currentDateTs+$offset))
done
The Brew Way
As I found out long after writing the above you can simply brew install coreutils and get a date command with the --date option.
The only thing to note there is this: Commands also provided by macOS have been installed with the prefix "g".
Read more…