Shutdown Proxmox VM using CLI

SSH into the Proxmox host and run: qm shutdown <VMID> This sends an ACPI shutdown signal to the guest OS for a graceful shutdown. To find the VM ID: qm list If the VM doesn’t respond to the shutdown signal, force it: qm stop <VMID> qm stop is equivalent to pulling the power cable. Use it only when qm shutdown hangs.

How to count words in a PDF from the Linux command line

The simplest approach: pdftotext input.pdf - | wc -w pdftotext is in the poppler-utils package (sudo apt install poppler-utils or sudo yum install poppler-utils). The - sends output to stdout instead of a file. Other options pdfminer: pdf2txt.py input.pdf | wc -w Install with pip install pdfminer.six. Python with PyPDF2: import PyPDF2 with open("input.pdf", "rb") as f: reader = PyPDF2.PdfReader(f) total = sum(len(page.extract_text().split()) for page in reader.pages) print(total) Note: PyPDF2’s PdfFileReader and getPage() are deprecated in newer versions — use PdfReader and index into reader.pages instead. ...

How to avoid other pods from being scheduled on your node in Kubernetes

Taints on nodes repel pods. Tolerations on pods let them ignore specific taints. Together they give you control over scheduling. Taint effects NoSchedule — pods without a matching toleration won’t be scheduled on the node. PreferNoSchedule — the scheduler avoids the node but will use it if there’s nowhere else. NoExecute — pods without a matching toleration are evicted and won’t be rescheduled there. Applying a taint kubectl taint nodes node1 type=db:NoSchedule This prevents any pod from being scheduled on node1 unless it has a toleration for type=db. ...

Remove lines matching a pattern from files recursively in Linux

find . -name "*.md" -type f -exec sed -i '/pattern/d' {} \; This one-liner walks the directory tree, finds every .md file, and strips out any line that matches the given pattern. The sed -i edits each file in place, and the {} gets swapped out for whatever path find hands it. Breaking it down find . -name "*.md" -type f does the walking. The -type f bit is important – without it, find would also match directories and pass them to sed, which would error out. The -exec ... \; at the end runs the command for each file individually. ...

Installing PhantomJS on Ubuntu 22.10

PhantomJS is a headless browser, which means it runs without a graphical interface and lets you automate web page interactions through scripting. I needed it for some automated testing at work and ran into a few things worth writing down, mostly because half the guides out there are either outdated or assume you already know what you’re doing. The version we’re installing is 2.1.1, which is the last release. The project has been unmaintained since 2017, but it still does what it needs to do for basic scraping and screenshot tasks. ...

Deleting files by content match in Linux

There are two ways to interpret this question, and the answer changes completely depending on which one you mean. Deleting files by filename If you want to nuke every file whose name contains a particular string: find . -type f -name '*string*' -delete The -type f keeps it from touching directories. The -delete flag removes whatever find matches. Simple enough. A word of caution: test without -delete first. Run the same command and replace it with -print to see what would actually get deleted. I’ve lost files to typos in wildcard patterns more times than I care to admit. ...

Grabbing an SSL certificate from a remote server

There are moments when you need to inspect the certificate a remote server is presenting – maybe it’s expired and you’re trying to work out why things are breaking, or maybe you need the raw certificate data for some other reason and don’t have access to the server’s configuration. The quickest way is with openssl s_client: openssl s_client -connect {HOSTNAME}:{PORT} -showcerts Replace {HOSTNAME} with the server address and {PORT} with the port (usually 443 for HTTPS). The -showcerts flag dumps the full certificate chain rather than just the leaf certificate. ...

Count directories in the current folder with a one-liner

A common question that comes up when you’re first getting comfortable with the command line: how do you count just the directories in your current folder? The quick answer is: ls -1 | wc -l This pipes a one-per-line listing of everything in the current directory into wc -l, which counts lines. Simple enough. But there’s a catch. This counts everything – files, symlinks, hidden items, the lot. If you only want directories, you need to be a bit more selective. ...

Count files in a directory with a one-liner

Another quick command line question: how do you count just the files in a directory, excluding subdirectories and other stuff? The classic answer: ls -l . | egrep -c '^-' This lists everything in long format (ls -l), then counts lines that start with a hyphen – which is how ls marks regular files. Directories show up as d, symlinks as l, and so on, so the regex filters them out. It works, but it’s a bit of a trick and relies on understanding ls output format. A more straightforward approach uses find: ...

Fix casks with `depends_on` that reference pre-Mavericks

If you get an error like Error: Cask 'hex-fiend-beta' definition is invalid: invalid 'depends_on macos' value: ":lion", where hex-fiend-beta can be any cask name and :lion any macOS release name, run the following command: /usr/bin/find "$(brew --prefix)/Caskroom/"*'/.metadata' -type f -name '*.rb' -print0 | /usr/bin/xargs -0 /usr/bin/perl -i -pe 's/depends_on macos: \[.*?\]//gsm;s/depends_on macos: .*//g' This strips out all depends_on macos references from installed casks. It’s a blunt instrument – you’re editing Homebrew’s metadata files directly – but it gets things working again. ...

How to run VLC player as root user

I ran into this a while back when I needed VLC running as root on a headless server, and the usual --no-sandbox flag didn’t cut it. VLC refuses to start as root by default, which makes sense from a security standpoint but is annoying when you actually need it. The fix is brutal and hacky, but it works: sed -i 's/geteuid/getppid/' /usr/bin/vlc What’s actually happening here? VLC’s startup script checks whether the effective user ID is zero (root). If it is, it bails out. By swapping geteuid with getppid, we’re telling the script to check the parent process ID instead of the effective UID. Since getppid() returns a number way bigger than zero, the check passes and VLC starts. ...

Update all globally installed npm packages at once

I keep meaning to run this but always forget the flag. There’s no npm update-all or anything – it’s just: npm update -g The -g tells npm to operate on the global package registry instead of the local node_modules. Without it, npm update only touches packages listed in your project’s package.json, which is the default behaviour and what you want most of the time. One thing to bear in mind: npm update won’t bump you to a new major version, even if one’s available. It respects the semver range in whatever pinned your package – so if you installed commander@2.x and 4.x is out, you’ll stay on 2.x. If you actually want to upgrade majors, you need to be explicit: ...

'Decoding the Error: StatusCode=0 "ReferencedResourceNotProvisioned" in Azure'

Introduction If you’re working with Azure, you might have seen an error like this: “Failure sending request: StatusCode=0 — Original Error: Code=‘ReferencedResourceNotProvisioned’ Message=‘Cannot proceed with operation because resource used by resource is not in Succeeded state. Resource is in Updating state and the last operation that updated/is updating the resource is PutSubnetOperation.’” It looks worse than it is. Here’s what it means and how to fix it. Why Does This Error Occur? A related resource is stuck in an ‘Updating’ state, so Azure won’t let the operation proceed. This usually means another operation is still running on that resource or one it depends on. ...

Import a Resource to a Terraform Module

Importing an existing AWS instance into a Terraform module is straightforward, but the syntax trips people up because you need to specify the full module path. terraform import module.foo.aws_instance.bar i-abcd1234 The format is module.<module_name>.<resource_type>.<resource_name>, followed by the resource ID. In this case, foo is the module name, aws_instance is the resource type, bar is the resource name inside that module, and i-abcd1234 is the AWS instance ID. Once imported, Terraform will manage the instance and track any configuration drift going forward.

Terraform Modules in Subdirectories

Terraform modules are usually at the root of a repository. Sometimes they’re nested in a subdirectory, and you need to point Terraform at the right one. Terraform handles this with a double-slash (//) in the source path. Everything after the // is treated as a subdirectory within the package. How It Works The syntax is straightforward: module "consul" { source = "hashicorp/consul/aws//modules/consul-cluster" } The hashicorp/consul/aws part is the module registry path. The //modules/consul-cluster tells Terraform to look inside that package for the actual module. ...

Merging Unrelated Git Histories

You’ve got two repositories with completely separate histories, and you need to bring them together. Maybe it’s an old project you’re absorbing into a new one, or a submodule that started life as its own thing. You try a standard git merge and Git immediately shuts you down: fatal: refusing to merge unrelated histories This isn’t a bug – it’s Git being cautious. When two branches share no common ancestor, Git assumes you’ve made a mistake and refuses to play along. But sometimes you genuinely want this merge, and there’s a flag for that. ...

Firefox OS Clock app running on Ubuntu with Firefox Marketplace in the background

Running Firefox OS apps on Ubuntu Linux

Mozilla announced Firefox OS back in 2011 under the codename Boot2Gecko, and since then the project has gone from a concept to something you can actually run on your desktop. I’ve been following it closely and finally got around to setting it up on my Ubuntu machine. Here’s how. What is Firefox OS? Firefox OS is Mozilla’s attempt at building a mobile operating system entirely from web standards. There’s no Java, no native SDK, no proprietary frameworks. The entire user interface – called Gaia – is built in HTML, CSS, and JavaScript. The rendering engine underneath is Gecko, the same one that powers Firefox. And at the bottom, it runs on a Linux kernel. ...

Replacing an IP address with sed

Sometimes you need to swap an IP address out of a file. Maybe you are moving a server to a new host, updating a config, or just tired of grepping through logs to find the old address. Whatever the reason, sed makes it trivial. The trick is matching the dotted-decimal pattern. An IP address is four groups of numbers separated by dots, so the regex needs to capture that structure. Here is the one-liner: ...

Disable services in Solaris 10

Managing services on Solaris 10 is nothing like Linux. There are no /etc/init.d/ scripts, no service command, no chkconfig. Instead, Solaris uses SMF — the Service Management Facility — and everything goes through svcadm. If you are new to Solaris, this can feel unnecessarily complicated. It is not, once you learn the pattern. Disabling a service You need root privileges or sudo access. The command is: svcadm disable network/cswpuppetd:default The argument is the service FMRI (Fault Management Resource Identifier). For Puppet installed from OpenCSW, the FMRI is network/cswpuppetd:default. The :default part refers to the default instance of the service. Some services have multiple instances, but most only have one. ...

Puppet logs on Solaris 10

Puppet on Solaris 10 stores its logs in the SMF log directory, which is different from the /var/log location you might be used to on Linux. If you are looking for the usual log files and cannot find them, this is probably why. Agent logs The Puppet agent (puppetd) runs as an SMF service, and its log is at: /var/svc/log/network-cswpuppetd:default.log To watch it in real time: tail -f /var/svc/log/network-cswpuppetd:default.log Master logs The Puppet master (puppetmasterd) follows the same pattern: ...