Skip to content

Instantly share code, notes, and snippets.

View JPvRiel's full-sized avatar

Jean-Pierre van Riel JPvRiel

  • South Africa, Johannesburg
View GitHub Profile
@JPvRiel
JPvRiel / bash_history_to_syslog.md
Last active May 2, 2025 15:06
Notes on (ab)using bash history to record commands to syslog

Logging bash history to syslog

Overview

Bash history was a convenience feature to help a user recall previous commands and not intended to meet any security requirements.

The Linux audit system (or alternate kernel level audit OS facility) is a more robust way to ensure user and process log events are recorded.

Security issues with bash history files and $BASH_COMMAND

@JPvRiel
JPvRiel / docker-compose
Last active December 23, 2016 15:11
sudo_docker_compose_workaround
#!/usr/bin/env bash
if [ -z "$VIRTUAL_ENV" ] || [ "$VIRTUAL_ENV" -ne "/home/a211278l/bin/python-venvs/docker" ]; then
source ~/bin/python-venvs/docker/bin/activate
fi
sudo -E "$(which docker-compose)" $@
deactivate
@JPvRiel
JPvRiel / gnome_proxy_to_env.md
Last active May 24, 2023 12:15
a shell wrapper to pull org.gnome.proxy settings into env, e.g. http_proxy, which is useful for .desktop files

Why?

Useful for:

  • updating current terminal's shell env proxy settings, or
  • wrapping exec in .desktop files to inject env proxy settings

GNOME proxy settings should normally get propergated into the shell (bash) environment via gnome-terminal, e.g. http_proxy and no_proxy. However:

  • I noticed that applications exectuted via .desktop entries sometimes don't work. This happens when an app ignores org.gnome.proxy settings but can often use proxy env vars from the shell.
  • If you're proxy settings change, existing shell processes will still have the old proxy enviroment variables, so this can help refresh them whithout having to create a new shell.
@JPvRiel
JPvRiel / deb_apt_dpkg_locked.md
Created February 16, 2017 10:37
Troubleshoot "Could not get lock /var/lib/dpkg/lock" errors when trying to update or install debian packages

Troubleshoot "Could not get lock /var/lib/dpkg/lock" errors when trying to update or install debian packages

Error Message

E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

@JPvRiel
JPvRiel / journalctl_enable_persistent_storage.md
Last active November 17, 2024 20:29
Enable persistent storage for the systemd journal log

Enable persistent storage for the systemd journal log

Overview

The assumed default setting in /etc/systemd/journald.conf is Storage=auto which implies that systemd journaling will only persist the journal if the expected storage location is available. Otherwise, the journal data is stored in memory and lost between reboots. On Ubuntu 16.04, /var/log/journal does not exist by default. Create it to keep and query events from previous boots.

Considerations:

  • Syslog still provides the persistant log records for Ubuntu 16.04, so enabling persistant systemd journal logging does cause a level of duplicaiton.
  • There are sane defaults:
@JPvRiel
JPvRiel / Find out which process has created an X window.md
Created March 24, 2017 09:22
Find out which process has created an X window

Overview

W window has a _NET_WM_PID property set by the applicaiton. To really validate if the application has set this correctly is more work (see reference).

Simple Example

Run command and click the window

$ xprop _NET_WM_PID
@JPvRiel
JPvRiel / decrypt_directory_of_pdfs_bash_qpdf.md
Created November 12, 2017 19:56
Decrypt a directory of PDFs using bash, basename and qpdf

Given a working directory and a folder c with encrypted PDFs, use qpdf, basename and a bash loop:

for f in c/*.pdf; do qpdf --password=<password> --decrypt $f "$(basename -s .pdf $f).pdf"; done
@JPvRiel
JPvRiel / git_workflow.md
Last active June 22, 2019 08:00
git workflow

Merging

Merge master into branch

A good idea if upstream has had commits and, to catch up, you need to test your feature branch with changes from upstream included

git checkout feature
git pull origin master
@JPvRiel
JPvRiel / spice-guest-tools Windows 10 BSOD.md
Last active September 4, 2018 17:59
Fixing "page fault in nonpaged area" Windows 10 BSOD caused by installing spice-guest-tools

Synopsis

Boot failure was caused by installing spice-guest-tools which, if you read details about it, also includes the QXL driver and the install broke my Windows 10 build 17134 guest somehow. This occured on Ubuntu 16.04 LTS with QEMU emulator version 2.5.0.

Error

BSOD with "page fault in nonpaged area" occurs after installing spice-guest-tools-latest.exe. It possibly clobbers other stable/good versions of drivers.

Automatic boot repair fails. After going through advanced options and getting to a command prompt, inspect the boot repair logs:

@JPvRiel
JPvRiel / ps_command_examples.md
Created September 4, 2018 18:00
`ps` command examples

Show top 10 processes by resident memory set size

ps -eo pid,user,rsz,vsz,comm,args --sort -rss --cols 160 | head -n11