Linux Fu: Debugging Bash Scripts

A recent post about debugging constructs surprised me. There were quite a few comments about how you didn’t need a debugger, as long as you had printf. For that matter, we’ve all debugged systems where you had nothing but an LED to flash or otherwise turn on to communicate with the user. However, it is hard to deny that a debugger can help with complex code.

To say you only need printf would be like saying you only need machine language. Technically accurate — you can do anything in machine language. But it sure makes things easier to have an assembler or some language to help you work out your problem. If you write a simple bash script, you can use the equivalent to printf — maybe that’s the echo command, although there is usually a printf command on a typical system, if you want to use it. However, there are other things you can do with bash including a pretty cool debugger if you know how to find it.

I assume you already know how to use echo and printf, but let’s dig into how to use trace execution line by line without the need for echo statements on every other line. Along the way, you’ll learn how to get started with the bash debugger.

Continue reading “Linux Fu: Debugging Bash Scripts”

Weird Substances: Hagfish Slime

In the cold, dark recesses of ocean floors around the world, hagfish slither around like sea snakes, searching for food. When a hagfish finds a suitable carcass, it devours the dead fish in two different ways. As it burrows face-first through the tissue, eating with its jaw-less, tentacled mouth, the hagfish also absorbs nutrients through its skin.

Hagfish are not the unholy result of dumping toxic waste in the ocean. They’re one of the oldest creatures on Earth, having been around for more than 300 million years. How have they lasted this long?

A coiled hagfish reveals its slime ports. Image via Oregon Coast Aquarium

These ancient creatures have no eyes, no backbones, and no scales. They are often misidentified as eel, and often called ‘slime eels’, but they are definitely fish. They just don’t look like conventional fish. In fact, when conventional, gill-faced fish come after hagfish, those guys are in for a surprise, because hagfish have a disgusting but ingenious defense mechanism.

Whenever hagfish are attacked or even just stressed by nearby fish or curious grabby humans, they immediately emit amazing amounts of mucus at an alarming rate. At the same time, the hagfish shoots out silky strands of protein that hold the slime together in a cohesive blob. Any predator that tries to bite down on one of these velvety frankfurters of the deep sea will find its mouth and gills covered in a wad of suffocating slime.

How is it that hagfish haven’t slimed themselves out of existence? Whenever they get get a taste of their own medicine, these boneless noodles quickly twist themselves into a pretzel. In the same motion, they use their paddle-shaped tails to squeegee off the slime.

Continue reading “Weird Substances: Hagfish Slime”

Patch, Or Your Solid State Drives Roll Over And Die

Expiration dates for computer drives? That’s what a line of HP solid-state drives are facing as the variable for their uptime counter is running out. When it does, the drive “expires” and, well, no more data storage for you!

There are a series of stages in the evolution of a software developer as they master their art, and one of those stages comes in understanding that while they may have a handle on the abstracted world presented by their development environment they perhaps haven’t considered the moments in which the real computer that lives behind it intrudes. Think of the first time you saw an SQL injection attack on a website, for example, or the moment you realised that a variable type is linked to the physical constraints of the number of memory locations it has reserved for it. So people who write software surround themselves with an armoury of things they watch out for as they code, and thus endeavour to produce software less likely to break. Firmly in that arena is the size of the variables you use and what will happen when that limit is reached.

Your Drive Is Good For About 3 Years And 9 Months

Sometimes though even developers that should know better get it wrong, and this week has brought an unfortunate example for the enterprise wing of the hardware giant HP. Their manufacturer has notified them that certain models of solid-state disk drives supplied in enterprise storage systems contain an unfortunate bug, in which they stop working after 32,768 hours of uptime. That’s a familiar number to anyone working with base-2 numbers and hints at a 16-bit signed integer in use to log the hours of uptime. When it rolls over the value will then be negative and, rather than the drive believing itself to be in a renewed flush of youth, it will instead stop working.

Egg on the faces of the storage company then, and an urgently-released patch. We suspect that if you own a stack of these drives you will already know about the issue and be nervously pacing the racks of your data centre.

Continue reading “Patch, Or Your Solid State Drives Roll Over And Die”

Teardown: 168-in-1 Retro Handheld Game

The holidays are upon us, and that can mean many furrowed brows trying to figure out what token gift they can give out this year as stocking-stuffers. Something that’s a bit more interesting than a coupon book or a lotto scratcher, but also affordable enough that you can buy a few of them without having to take part in that other great holiday tradition: unnecessary credit debit.

Includes the NES classic Super Militarized Police Bros 3

Which is how I came to possess, at least temporarily, one of these cheap handheld multi-games that are all over Amazon and eBay. The one I ordered carries the brand name Weikin, but there are dozens of identical systems available, all being sold at around the same $20 USD price point. With the outward appearance of a squat Game Boy, these systems promise to provide precisely 168 games for your mobile enjoyment, and many even include a composite video out cable and external controller for the less ambulatory classic game aficionado.

At a glance, the average Hackaday reader will probably see right through this ploy. Invariably, these devices will be using some “NES on a Chip” solution to emulate a handful of legitimate classics mixed in with enough lazy ROM hacked versions of games you almost remember to hit that oddly specific number of 168 titles. It’s nearly a foregone conclusion that at the heart of this little bundle of faux-retro gaming lies a black epoxy blob, the bane of hardware tinkerers everywhere.

Of course, there’s only one way to find out. Let’s crack open one of these budget handhelds to see what cost reduction secrets are inside. Have the designers secured their place on the Nice List? Or have we been sold the proverbial lump of coal?

Continue reading “Teardown: 168-in-1 Retro Handheld Game”

Chandrayaan-2 Found By Citizen Scientist; Reminds Us Of Pluto Discovery

What does Pluto — not the dog, but the non-Planet — have in common with the Vikram lunar lander launched by India? Both were found by making very tiny comparisons to photographs. You’d think landing something on the moon would be old hat by now, but it turns out only three countries have managed to do it. The Chandrayaan-2 mission would have made India the fourth country. But two miles above the surface, the craft left its planned trajectory and went radio silent.

India claimed it knew where the lander crashed but never revealed any pictures or actual coordinates. NASA’s Lunar Reconnaissance Orbiter took pictures several times of the landing area but didn’t see the expected scar like the one left by the doomed Israeli lander when it crashed in April. A lot of people started looking at the NASA pictures and one Indian computer programmer and mechanical engineer, Shanmuga Subramanian, seems to have been successful.

Continue reading “Chandrayaan-2 Found By Citizen Scientist; Reminds Us Of Pluto Discovery”

Retrotechtacular: The Gyro-X

In the 1950s, American automobiles bloomed into curvaceous gas-guzzlers that congested the roads. The profiles coming out of Detroit began to deflate in the 1960s, but many bloat boats were still sailing the streets. For all their hulking mass, these cars really weren’t all that stable — they still had issues with sliding and skidding.

One man sought to fix all of this by re-imagining the automobile as a sleek torpedo that would scream down the road and fly around turns. This man, Alex Tremulis, envisioned the future of the automobile as a two-wheeled, streamlined machine, stabilized by a gyroscope. He called it the Gyro-X.

Continue reading “Retrotechtacular: The Gyro-X”

Updating To Windows 10 For Fun And Profit: Make Those OEM Keys Go Further

Microsoft seems to have an every-other-version curse. We’re not sure how much of this is confirmation bias, but consider the track record of releases. Windows 95 was game-changing, Windows 98 famously crashed during live demo. Windows 2000 was amazing, Windows ME has been nicknamed the “Mistake Edition”. XP was the workhorse of the world for years and years, and Vista was… well, it was Vista. Windows 7 is the current reigning champion of desktop installs, and Windows 8 was the version that put a touchscreen interface on desktops. The “curse” is probably an example of finding patterns just because we’re looking for them, but the stats do show a large crowd clinging to Windows 7.

Windows 10 made a name for itself by automatically installing itself on Windows 7 and Windows 8 computers, much to the annoyance of many unexpecting “victims” of that free upgrade. Several years have gone by, Windows 10 has gotten better, and support for Windows 7 ends in January. If you’re tied to the Windows ecosystem, it’s time to upgrade to Windows 10. It’s too bad you missed out on the free upgrade to Windows 10, right?

About that… It’s probably an unintended side effect, but all valid Windows 7 and Windows 8 keys are also valid Windows 10 keys. Activation is potentially another issue, but we’ll get to that later.

Continue reading “Updating To Windows 10 For Fun And Profit: Make Those OEM Keys Go Further”