Sitemap
Balki Maharaj

Balki Maharaj

There is no tomorrow.

👨‍💻 Using Bash trap to Build Self-Diagnosing Scripts

4 min readAug 19, 2026

--

👁️ In large-scale automation, problems often arise not during startup, but when things go wrong. Temporary files are left behind, locks remain in place, and child processes keep running. Bash trap lets you intercept events and run your own cleanup, diagnostics, and state-saving logic before the script exits.

📝 Automatically cleaning up resources on exit

A function registered with trap ... EXIT runs whenever the script terminates, whether it finishes successfully or exits because of an error. This makes it much easier to prevent temporary files and other resources from being left behind.

#!/usr/bin/env bash
TMP_DIR=$(mktemp -d)
LOCK="/tmp/process.lock"
cleanup() {
echo "cleanup: removing resources"
rm -rf "$TMP_DIR"
rm -f "$LOCK"
}
trap cleanup EXIT
touch "$LOCK"
echo "working in $TMP_DIR"
sleep 30

📝 Collecting diagnostic information when something fails

When a command fails, Bash can capture useful context, such as the line number and command that caused the problem. This is particularly handy in CI/CD pipelines and server-side scripts, where reproducing a failure manually may be difficult.

debug() {
echo "command failed"
echo "line: $1"
echo "command: $2"
}
trap 'debug "$LINENO" "$BASH_COMMAND"' ERRset -emkdir /protected/path

📝 Handling process termination properly

If the script receives SIGTERM or SIGINT, you can use trap to stop child processes gracefully before the main script exits.

stop_worker() {
echo "stopping worker..."
kill "$WORKER_PID"
wait "$WORKER_PID"
}

trap stop_worker SIGTERM SIGINT
sleep 300 &
WORKER_PID=$!
wait

❗️ trap can turn an ordinary Bash script into a much more robust, manageable service: resources are cleaned up, failures are easier to diagnose, and shutdowns can be handled gracefully.

This approach is especially useful for deployment automation, database migrations, background jobs, and other tasks where an untidy shutdown can cause far more trouble than a few extra lines of Bash.

Tags: #bash #automation #devops #linux #scripting

Press enter or click to view image in full size

Apple Sends Spyware Warnings to Users in 110 Countries

Apple has issued a new wave of threat notifications to users around the world, warning about sophisticated targeted attacks involving commercial spyware similar to Pegasus.

According to Apple, these attacks have affected potential targets across 110 countries.

Who Are These Attacks Targeting?

These attacks generally aren’t aimed at ordinary users. Instead, they target specific individuals because of their professional activities.

Potential targets can include:

  • Journalists
  • Politicians
  • Human rights defenders
  • Diplomats
  • Other people handling sensitive information

Attackers use extremely sophisticated — and incredibly expensive — exploits capable of compromising devices without obvious signs of infection.

Some attacks are zero-click, meaning the victim may not need to click a malicious link, open an attachment, or take any action at all.

How Does Apple Notify Potential Victims?

Apple says it can notify users through several channels, including:

  • An alert on the device’s Lock Screen and in Settings
  • An email from threat-notifications@email.apple.com
  • A red warning banner when signing in to account.apple.com

Apple describes these notifications as high-confidence threat alerts.

Get Balki Maharaj’s stories in your inbox

Join Medium for free to get updates from this writer.

However, the company does not publicly disclose detailed technical information about the vulnerabilities or attack methods involved. Keeping those details private can make it harder for spyware developers to quickly modify their tools and bypass existing protections.

What Should You Do If You Receive an Alert?

Apple’s strongest recommendation for someone who receives a threat notification is to enable Lockdown Mode immediately.

Lockdown Mode significantly restricts certain device features and attack surfaces, including aspects of:

  • Web browsing and WebKit
  • Network connections
  • iMessage attachment handling
  • Link previews
  • Other services commonly abused by sophisticated exploits

The goal is to reduce the number of ways highly sophisticated spyware can compromise the device.

Should Ordinary Users Be Worried?

For most people, the likelihood of being targeted by extremely expensive commercial spyware is very low.

These operations are generally associated with highly targeted surveillance rather than mass attacks against random users.

However, journalists, researchers, activists, executives, government officials, and others who regularly handle sensitive information should take security warnings seriously.

The most important rule is simple:

If Apple sends you a threat notification, don’t ignore it.

Enable Lockdown Mode, update your devices, secure your accounts, and consider getting professional security assistance if you believe you may be specifically targeted.

Cybersecurity isn’t about being paranoid. It’s about understanding your risk — and responding appropriately when the warning is real.

Mistral Is Hosting Chinese AI Models — and Building a European GPU Empire

French AI company Mistral AI is changing the game.

The company is moving beyond simply developing proprietary and open-weight models and is positioning itself as a broader AI infrastructure provider.

🔍 Mistral has opened its cloud platform to third-party AI models, with China’s GLM-5.2 reportedly among the first models available. The model supports a context window of up to 1 million tokens.

⚡️ For the enterprise market, this represents a significant shift:

The Bigger Picture

Mistral may have recognized something important: building foundation models is an extraordinarily expensive and constantly shifting race.

Today’s leader can be challenged by a new model tomorrow.

But control over GPUs, data centers, cloud infrastructure, and the pipelines carrying AI workloads could provide strategic leverage regardless of which model ultimately wins.

The AI race may therefore be evolving from:

“Who has the smartest model?”

to:

“Who controls the infrastructure that runs them all?”

--

--