302 episoder
- This show has been flagged as Explicit by the host.
SUMMARY
The presenter outlines a practical cybersecurity workflow, covering ergonomic setups, browser isolation, virtual machine troubleshooting, AI-assisted scripting, and network tunneling methods utilized during active security assessments.
ONE-SENTENCE TAKEAWAY
Isolate browser environments, utilize automation scripts, and verify network paths before starting security tests to avoid workflow interruptions.
TOOLS
Talon Voice
– Open-source voice recognition software enabling hands-free computer control and command execution.
Obsidian
– Local-first markdown note-taking application supporting secure, AI-friendly knowledge management.
AutoHotkey
– Windows scripting utility for creating custom macros and remapping keyboard inputs.
Chrome Debug Commands
– Browser developer tools allowing direct inspection of extensions, cookies, and storage.
Whisper Diarization
– Audio processing script that separates speaker tracks and converts recordings to searchable text.
Hyper-V / WSL
– Microsoft virtualization platforms enabling isolated guest environments and Linux subsystem integration.
OpenConnect / OpenVPN
– Command-line tunneling clients used for establishing secure, split-tunnel network connections.
Jamboree Framework
– Portable PowerShell environment that dynamically provisions development tools without altering system paths.
MOBA Portable
– Feature-rich terminal emulator supporting static/dynamic tunnels, auto-reconnect, and embedded X-server capabilities.
Nmap
– Network discovery and security auditing tool utilized for comprehensive port scanning and service detection.
00:00:00 Ergonomic Workspace Configuration
Configures physical workstation elements to reduce strain during extended testing sessions. Proper alignment prevents repetitive stress injuries while maintaining focus on technical tasks.
Monitor Positioning
– Displays should align with eye level to maintain neutral neck posture; the speaker notes their curved 49-inch screen sits slightly high due to chair adjustments.
Split Keyboard Layout
– Utilizes a Freestyle 2 mechanical keyboard, allowing natural shoulder-width arm placement and reducing wrist deviation during prolonged typing.
Postural Adaptation
– Acknowledges that ergonomic equipment requires matching body alignment; elbow rests should sit between hip and shoulder height for optimal leverage.
01:45:00 Voice Control & Note Synchronization
Utilizes auditory input methods and localized knowledge bases to streamline documentation workflows. Separating secure work notes from casual observations prevents data contamination.
Talon Voice Integration
– Runs continuously to handle navigation, text entry, and application switching without manual keyboard interaction.
Obsidian Migration
– Transitions from cloud-based keep apps to local markdown files, enabling direct querying by local AI models while maintaining offline accessibility.
Note Categorization
– Divides information into secure work records and insecure personal logs, ensuring clean data pipelines for future retrieval and analysis.
03:50:00 Browser Extension Management & Security Isolation
Separates web browsing activities from primary work processes to minimize attack surfaces. Running dedicated user profiles prevents plugin conflicts and credential leakage.
Jailed User Accounts
– Creates restricted system profiles that only launch the browser, isolating extensions from core workstation operations.
Shared Folder Synchronization
– Establishes a single directory path bridging work and browsing users, allowing seamless file transfers without cross-contamination.
Extension Audit Process
– Leverages Chrome debug commands to enumerate installed plugins, verifying functionality before deployment on target networks.
06:15:00 Training Optimization & Audio Processing
Accelerates mandatory compliance viewing through speed manipulation and automated transcription. Converting video content into searchable text enables rapid information retrieval.
Global Speed Control
– Increases playback rates up to sixteen times normal speed, drastically reducing time spent on repetitive corporate training modules.
Whisper Diarization Pipeline
– Downloads video tracks, separates speaker voices, and generates timestamped transcripts for quick reference during assessments.
Download Management
– Employs multi-threaded swarm downloaders and classic turbo managers to handle bulk media retrieval without interrupting active workflows.
10:40:00 Virtualization & Network Tunneling Protocols
Establishes isolated testing environments using Windows virtual machines while managing connectivity constraints. Proper session handling prevents unexpected disconnections during remote engagements.
Enhanced Session Mode
– A Hyper-V feature providing higher resolution and shared clipboard functionality; disabling it is required before initiating certain VPN clients to avoid routing conflicts.
Split Tunneling Mechanics
– Routes specific traffic through the virtual network while keeping local resources accessible, preventing complete internet loss during connection tests.
Certificate Verification
– Identifies self-signed SSL mismatches early in the process, documenting them as preliminary findings before proceeding with authentication steps.
15:30:00 Macro Automation & Input Remapping
Remaps frequently used keyboard shortcuts to reduce physical strain and accelerate command execution. Running scripts with elevated privileges ensures reliable input registration across virtual environments.
Caps Lock Repurposing
– Converts the caps lock key into a primary modifier, assigning copy/paste functions to adjacent letters for faster workflow navigation.
Physical Typing Macros
– Simulates keystrokes with deliberate delays, allowing seamless data entry into restricted VM consoles that block standard clipboard operations.
Administrator Execution Requirement
– Highlights that macro scripts must run with elevated privileges to successfully inject inputs across different desktop sessions.
20:15:00 Portable Development Environments & Python Management
Deploys lightweight scripting frameworks that dynamically provision necessary tools without modifying host configurations. Verifying package contents prevents dependency conflicts during testing.
Jamboree Framework
– A PowerShell-driven utility that downloads and configures development stacks on demand, resetting environment variables to maintain system cleanliness.
NuGet Package Filtering
– Queries Microsoft's repository API to retrieve specific Python versions, ensuring compatibility with legacy tunneling scripts.
Binary Verification Process
– Checks extracted archives for bundled
pip.exe
or
pip3.exe
executables, eliminating manual module installation steps during rapid deployments.
28:40:00 AI-Assisted Scripting & Debugging Workflows
Generates and refines PowerShell functions through iterative conversational prompts. Validating AI output against actual system behavior prevents silent configuration errors.
Vibe Coding Approach
– Relies on continuous feedback loops with language models to draft, minimize, and debug automation scripts in real-time.
Parameter Standardization
– Enforces strict formatting rules for PowerShell commands, avoiding hardcoded paths and ensuring cross-environment compatibility.
Temporary Storage Management
– Monitors extraction directories to prevent disk saturation, redirecting large package downloads away from constrained system partitions.
35:10:00 Terminal Emulation & Advanced Tunneling Strategies
Facilitates complex network routing through dedicated terminal applications. Configuring dynamic and static tunnels enables reliable reverse connections for remote assessments.
MOBA Portable Configuration
– Utilizes an INI-based tunnel manager that automatically maintains connections across changing IP addresses or Wi-Fi networks.
Reverse Shell Routing
– Establishes outbound channels back to the tester, then proxies all subsequent traffic through those connections for consistent monitoring.
Proxy Chain Integration
– Forces non-proxy-aware applications to route through Burp Suite or custom interceptors using Windows utility wrappers like Priboxy.
42:30:00 Final Connectivity Testing & Engagement Wrap-Up
Executes comprehensive port scans to verify target accessibility before documenting findings. Acknowledging workflow detours ensures realistic time management during active engagements.
Nmap Verification
– Runs full-port scans with verbose output to confirm host responsiveness and identify open services prior to credential testing.
Connection Refusal Documentation
– Captures screenshot evidence of failed routing attempts, providing clear proof of network restrictions for client reporting.
Workflow Reflection
– Recognizes that exploratory debugging adds value but requires time boundaries; balancing thoroughness with engagement scope maintains professional efficiency.
Provide feedback on this episode. - This show has been flagged as Clean by the host.
As a child, I was so fond of reading what I saw as beautiful. Even when above [lacking] the understanding.
The perception of beauty came mainly from the cover and the fonts used (
same today
) or from the place the book occupied on my father’s shelf.
One of them was Tuareg. More than once I took this classic from the home library, only to glance at the first page with no interest. It was only decades later — some years ago — that I saw the title again, and read with pleasure and no difficulties. It’s not a hard read, even to a 12 year-old, probably only the argument, the plot, didn’t catch me by then.
Anyway, I was attracted to the book, as if simply wanting to read it made me part of the classic, the intellectual.
I have less of this today. [I mean,] Not the inability to read a lot of books, but the urge to be a consumer of certain cultural product. Maybe due to not greeding to build a personal image, content without exposition.
Still, sometimes, wanting to consume a piece of media and being unable to.. I wanted a story of robots, the book I though was not available [(All Systems Red)], so I bought one of scientific fiction.
Somehow it attracted me when I flipped the few pages of Planet of Exile at the bookstore, an item that could lead me to a travel outside of this place, an escape. At home, I immediately saw I couldn’t grasp it. There were too many characters (too many = more than two in the first page, specially when another atmosphere is the location, a new physics to grasp). Too much information, can’t retain the minimum necessary in the way to the second, third… fifth page, by when more is being presented. This was always a disability of mine, focused on a little tiny thing, intensely, for some time, all lost in some weeks or months. I know it happens to
me
, because people are able to remember the names of the cars of the movie Cars. Not an incredible feat
for them
(maybe they haven’t paid attention, nor actively tried to remember, only did), and something
strange
to me.
It was decided to register this because when I saw myself unable to read the [Ursula] Le Guin’s book, I got nervous. I’ve already been forgetting more ultimately, take confused steps, and now I can’t center on a book?! What’s happening?
But then I took a breath: much can be going way too wrong from current circumstances outside and inside, but your limited comprehension of the world (and its art) is very part of you. This trace, or frailty, of your character, is not your brain rotting, it’s part of what you have been since always.
Thank you.
Provide feedback on this episode. - This show has been flagged as Clean by the host.
In his early days as a writer, Heinlein wrote his stories in the context of a shared universe that he called the Future History. These were mostly short stories at first, with the occasional novella. But they include some great stories.
The Future History, Part 2
There were a few key themes running through Heinlein’s body of work. One we have already remarked upon, individual freedom, which had to be protected from any source of power, including both government and private corporations. This was essentially a libertarian perspective, but unlike many of today’s libertarians he was equally averse to the corporate type of power as a threat. But he had a complex view of the world which has resisted some attempts to pigeonhole him. He started out as a socialist, and while he didn’t remain one, he never became a knee-jerk reactionary either. In fact, he clearly despised them just as much. One way of looking at his body of work is that he explored the ramifications of different social policies through his stories, but in most cases the needs of a good story came first in the early years. In his later works he often surrendered to the temptation to pontificate, which reduced the enjoyment of them somewhat for anyone who was not already in agreement with his opinions
The second major theme you see throughout all of his works is the idea of the competent individual. He admired anyone who could do a job well, and clearly did not care whether they were man or woman, nor black or white. Alexei Panshin writes, in Heinlein in Dimension:
“There is one unique and vivid human Heinlein character, but he is a composite of Joe-Jim Gregory, Harriman, Waldo, Lazarus Long, Mr. Kiku, and many others, rather than any one individual. I call the composite the Heinlein Individual. . . . It is a single personality that appears in three different stages and is repeated in every Heinlein book in one form or another.
“The earliest stage is that of the competent but naïve youngster. . . . The second stage is the competent man in full glory, the man who knows how things work. . . . The last stage is the wise old man who not only knows how things work, but why they work, too.”
Harriman we have already encountered in The Man Who Sold The Moon, and the others appear later. The Heinlein Individual, as he is often referred to, appears in many of Heinlein’s stories.
A third major theme has to do with morality and religion. Heinlein grew up in what he considered the heart of the Bible Belt, in Missouri, and saw first-hand how the evangelical Christians operated, and despised what he saw. As someone who believed in individual freedom, he could never surrender to someone else’s idea of how he should live his life. He saw them as a danger to his ideal libertarian society, and this shows up very early in his work. He personified the good, upright, church-going folk as “Mrs. Grundy”, and while you might want to draw the drapes to keep her from knowing what you were doing, you should never let her dictate how you would live your life. Revolt in 2100 begins the exploration of this in detail.
There is a chart of the future history at Baen Books, and in it we see that the 1960s were what Heinlein called The Crazy Years. (Remember, he conceived this in the 1940s and 1950s.) But in 2012 the major thing occurred when Nehemiah Scudder, a backwoods preacher, managed to get elected as President. This would be the last election held under the U.S. Constitution as he established a religious dictatorship that lasted a couple of generations. IS this plausible? Heinlein wrote about this:
“As for … the idea that we could lose our freedom by succumbing to a wave of religious hysteria, I am sorry to say that I consider it possible. I hope that it is not probable. But there is a latent deep strain of religious fanaticism in this, our culture; it is rooted in our history and it has broken out many times in the past.
“It is with us now; there has been a sharp rise in strongly evangelical sects in this country in recent years, some of which hold beliefs theocratic in the extreme, anti-intellectual, anti-scientific, and anti-libertarian.“
His background in the Bible Belt is what informs a lot of his thinking. He goes on to describe how this might happen:
“Throw in a Depression for good measure, promise a material heaven here on earth, add a dash of anti-Semitism, anti-Catholicism, anti-Negroism, and a good large dose of anti-“furriners” in general and anti-intellectuals here at home, and the result might be something quite frightening — particularly when one recalls that our voting system is such that a minority distributed as pluralities in enough states can constitute a working majority in Washington.”
As the science fiction author David Brin points out, Heinlein accurately predicted much of what we are going through in the United States right now. There is an emerging dictatorship in the United States, promoted by right-wing religious groups. The “material heaven here on earth” is represented by the Prosperity Gospel, prominent in the Trump movement, and so on. Where the Prophet used a restored Ku Klux Klan as his muscle, we have The Proud Boys, and so on. It really does track very closely. Read David Brin’s article for more on this.
But nothing lasts forever. Empires rise and fall, governments change, and in this case a resistance movement arises. The revolt is depicted in the novella If This Goes On— (1940), and it is set in the year 2100, giving the title to the book. The main character is John Lyle, who is a young army officer assigned to the group protecting The Prophet in his capital of New Jerusalem. In the beginning he is thoroughly indoctrinated, but then begins to question his beliefs when he falls for one of The Prophet’s virgins, Sister Judith. He has an older companion in the military who is not only unshocked when John confides in him about his doubts, but offers to help him. It turns out this companion, Zeb Jones, is a member of the underground group called The Cabal that is working to overthrow the theocracy. In the end they are successful, and in the course of this John Lyle does a lot of growing up. In this we see another common characteristic of Heinlein stories: a young, naive boy meets up with an older and wiser man who helps him to grow.
In 2016 If This Goes On— won the Retro-Hugo Award for best novella of 1940. And in a personal note, I have T-shirt that says “Scudder for President 2012”. This baffles most people, but I enjoy the in-joke.
What is interesting in this book is that Heinlein doesn’t stop with a successful revolution. He then goes on in a second novella to describe the government that arose following the revolution, and this story is called Coventry (1940). The new government that arises after the revolution is called The Covenant, and it is an attempt to make sure that what happened with Scudder in 2012 could never happen again. It is a strongly libertarian government based on an agreement to be non-violent. In this society, scientists can cured criminal or violent tendencies, but any citizen convicted of such must agree to the treatment. The alternative to treatment is that they can be exiled to a place called Coventry. Coventry is outside of the Covenant society, and the Covenant society has nothing to do with them.
Our protagonist, David McKinnon, is convicted of assault, and chooses to go to Coventry instead of getting treatment. He imagines it is a peaceful anarchy, but is disabused of this notion when he is robbed of all of this possessions upon entry and thrown in jail. A fellow inmate, Fader Magee, helps him escape, and we learn he is an agent of the Covenant government. They learn that two of the factions in Coventry have joined forces, and found a way to break through the barrier that surrounds Coventry. They plan to attack and overthrow the Covenant government. David and Fader separately work to escape and get back to warn the Covenant government, which they do successfully. And by doing this, David has demonstrated that he is no longer a danger to the Covenant society and no longer subject to treatment.
This story won a Prometheus Hall of Fame Award, which is awarded by the Libertarian Futurist Society. And the Covenant society certainly has libertarian features. But this is not the Randian version of libertarianism, as exemplified by the fact that David is restored to the society because he demonstrated his concern for others. Heinlein always promoted individual freedom, but also the idea that people have a responsibility towards others.
Finally, Revolt in 2100 contains the short story Misfit, w2hich we have looked at previously.
The Past Through Tomorrow (1967) is a one volume collection of most of the Future history stories. I say most because just which stories belonged in this group could change from time to time. It also has the last version of the Chart of the Future History, and a few stories we have not yet mentioned (Methusaleh’s Children, and The Menace From Earth). And many of his other works contain back references to these events that imply that they might be set in the same alternate universe. Heinlein gets the last word on this:
“I have never been sure whether or not publishing that chart was a good idea or a bad mistake. Possibly it helped to sell some stories later—but certainly it caused me and still causes me to receive a lot nuisance mail from nitpickers. I have never felt bound by that chart; it was to serve me, not the other way around. If I found myself with a good story notion which fitted fairly well into the chart but not perfectly, I shed no tears—I went ahead and let the inconsistencies stand.
I want each story to be internally consistent . . . but I won’t let myself be painted into a corner through trying to fit that chart perfectly. I may start another “Future History” story tomorrow . . . and find that to make it a good yarn I must violate some item on that chart. I’ll give the nitpickers something to pick, for I will not hurt a good yarn for the sake of “logic”—logic is not involved, as that chart is fiction, not Holy Writ.”
Links:
https://www.amazon.com/Heinlein-Dimension-Critical-Alexei-Panshin/dp/0911682015
https://web.archive.org/web/20151105170345/http://www.baenebooks.com/chapters/1439133417/1439133417___1.htm
https://david-brin.medium.com/heinleins-future-history-coming-true-before-our-eyes-10356a95556a
https://en.wikipedia.org/wiki/%22If_This_Goes_On%E2%80%94%22
https://en.wikipedia.org/wiki/Coventry_(short_story)
https://en.wikipedia.org/wiki/Prometheus_Award#Hall_of_Fame_Award_inductees
https://en.wikipedia.org/wiki/The_Past_Through_Tomorrow
https://www.palain.com/science-fiction/the-golden-age/robert-a-heinlein/the-future-history-part-2/
Provide feedback on this episode. - This show has been flagged as Clean by the host.
Kevie, Paul and Dave are back once again with the HPR Beer Garden, this time focusing on the relatively new style of beer called Double IPA. Kevie samples
Man Overboard
by
Cromarty Brewing
, Paul tastes
Rumble
by
Beavertown
and Dave opts for
Ultra Phase by North Brewing
Connect with the guys on Untappd:
Dave
Paul
Kevie
The intro sounds for the show are used from:
https://freesound.org/people/mixtus/sounds/329806/
https://freesound.org/people/j1987/sounds/123003/
https://freesound.org/people/greatsoundstube/sounds/628437/
The next 3 beer styles to be reviewed:
Belgian Blonde
DDH IPA
Amber Ale
Provide feedback on this episode. - This show has been flagged as Clean by the host.
01 Introduction
In this episode I will describe how to calculate elapsed time in bash or other shell scripts.
While this may sound like a very simple and basic thing to do, there is a slightly more complex aspect to it if you wish to calculate elapsed time to a higher resolution than one second.
02
There are many reasons for calculating elapsed time in a shell script.
For example you may wish to simply report how long an operation took to run.
Another reason may be that you are trying to speed up a script and need to calculate benchmark data to see how different alternative methods perform.
03
What may seem like a simple task gets a bit more complicated if you want to do it for multiple different operating systems even if they are all unix related, as we shall see.
--------------------
04 Operating Systems Tested
For the purposes of this episode, I ran tests on the current version of the following operating systems.
Alma
Alpine
Debian
FreeBSD
OpenBSD
RaspberryPi
OpenSuse
Ubuntu 2604
Alma is a close copy of Red Hat that we can take as representing Red Hat style distros.
--------------------
05 Simple Low Resolution Timing
I will start with the simple and obvious method before describing the less obvious ones.
This uses the date command to get the current time in seconds since the unix epoch.
This is simply
date '+%s'
06
Save this to a variable using whatever method you prefer.
For example.
starttime=$(date '+%s')
07
Next, do whatever operations it is you wish to time.
Use the date command to get the current time again.
endtime=$(date '+%s')
08
Now simply subtract the start time from the end time using shell arithmetic.
This should be very obvious and basic.
--------------------
09 Higher Resolution Timing
However, suppose we wish to measure time to greater than one second of precision.
We need to do two things.
The first is to obtain the current time at a higher degree of precision.
The second is to conduct the calculations to a higher degree of precision.
10
Unfortunately, the standard time precision for POSIX shells seems to be 1 second.
Some shells offer a higher precision, but others do not.
Furthermore, standard shell arithmatic uses integer, which limits calculations to 1 second of precision.
--------------------
11 Bash High Resolution Shell Variable
Fortunately, bash is one that does offer a high precision date.
If you are using bash 5.0 or newer, there is a shell variable called EPOCHREALTIME which offers time since the the unix epoch (that is, since the first of January 1970, at 00:00:00 UTC) in seconds to 6 decimals of precision.
12
Example
echo $EPOCHREALTIME
1779634800.184926
13
This is related to the similar bash variable known as EPOCHSECONDS which gives the number of seconds since the unix epoch.
14
Example
echo $EPOCHSECONDS
1779634800
15
So if you are using bash, measuring time is very simple.
--------------------
16 But is it Really Bash?
Is your script however actually using bash?
Debian and derivatives actually have two shells.
The first, the interactive shell is bash.
The second, the non-interactive shell is dash, which stands for "debian almquist shell".
17
If you open a terminal, you get bash.
If your script starts with a "bin/bash" shebang line, you get bash.
However, if your script starts with a "bin/sh" shebang line, you get dash.
Some people find themselves getting caught out by this one when they try something out in a terminal but find that it doesn't work in their script which started with "bin/sh".
18
Many other, but not all, Linux distros use bash for both the interactive and non-interactive shells, so "bin/sh" and "bin/bash" work the same with those ones.
So if you intend to use bash, make sure your script calls for bash in the first line.
--------------------
19 The SHELL Variable
So how can a script tell what shell it is running under?
There is a shell variable called "SHELL" which will tell you the name of the shell.
Well, sort of.
20
On Debian and derivatives "SHELL" will say "bash" regardless of whether the actual shell is bash or dash.
On some other operating systems "SHELL" will simply say "sh" even if it is something else entirely.
So we need to do some additional levels of checking to see what we have.
21
To start with though, here's what each of the test distros reports for SHELL.
Alma : bash
Alpine : sh
Debian : bash
FreeBSD : sh
OpenBSD : ksh
Raspberry-Pi : bash
Suse : bash
ubuntu2604 : bash
--------------------
22 Bash Versus Dash
First, let's try to see which ones are bash and which ones are dash.
The first thing we can check is for the shell variable BASH_VERSION.
23
Example
echo $BASH_VERSION
If the shell is bash, then it will report a version string.
If the shell is not bash, then it will return an empty value.
24
Using this test, we can see that Alma and Opensuse are indeed using bash.
We however need to check Debian, Raspberry Pi, and Ubuntu when running in an "sh" script.
To check this we can use the "which" command to see what "sh" actually is.
25
Example
echo $( ls -l $(which sh ) | rev | cut -d" " -f1 | cut -d/ -f1 | rev )
26
"which sh" shows us the path to "sh"
However, that is a link so we need to use
"ls -l" to find the actual executable.
"rev" reverses the string.
27
"cut" takes the first element separated by spaces.
The second
"cut" takes the first element separated by the "/" characters.
The final "rev" takes that string and reverses it again to get it in the correct order.
28
In the case of Debian, Raspberry Pi, and Ubuntu it tells us that this is "dash".
--------------------
29 Openbsd
Openbsd reports its shell as "ksh", which stands for Korn Shell.
It is indeed Korn Shell, so we simply leave that one as is.
--------------------
30 Alpine and Freebsd
Next we have Alpine Linux and Freebsd, which both report as "sh".
In the case Freebsd there doesn't appear to be any further we can go that I am aware of.
It's simple "sh".
It is a basic POSIX shell which seems to be similar to the original unix shell, the Bourne Shell.
Older versions of Freebsd used a different shell known as tsch (the C shell), but I haven't tested that so I will ignore that here.
31
With Alpine Linux however, we can get the actual shell using the same method that we used for Debian Linux.
This reports as being "busybox".
32
Busybox is a limited shell intended for use in embedded systems.
Alpine was originally an embedded distro, but some people started using it for containers.
Alpine is Linux, but it is not GNU/Linux, and there are a number of areas which can trip you up if you are not aware of them.
So, be extra careful if you are using it for anything, and test everything.
--------------------
33 Summary of Actual Shells
Here is our revised list with the actual shell used when asking for "sh", so far as we can determine.
Alma : bash
Alpine : busybox
Debian : dash
FreeBSD : sh
OpenBSD : ksh
Raspberry-Pi : dash
Suse : bash
ubuntu2604 : dash
34
There are other shells, but none of them are the default shell for any of the distros on our list, so I haven't tested them.
--------------------
35 Solutions for Measuring Time
Now we need to find solutions for bash, dash, ksh, sh, and busybox.
--------------------
36 Bash
For bash, we can simply use EPOCHREALTIME, as mentioned above.
--------------------
37 Dash
For dash, we can use the date command.
This is a very conventional method, and is probably the first answer that anyone would give for this situation.
However, while it will work in most cases, it will not work in all cases, so it is not a universal solution.
38
To use date we simply call it with the correct format string.
This uses %s to get seconds since the epoch, and %N to get nanoseconds of the current second.
If you put a decimal separator between the two it will appear in the output.
You can use the correct decimal separator for your locale, but I won't go into that here.
Instead I will just assume a period or dot.
39
Example
date '+%s.%N'
1779634800.358916385
--------------------
40 Problems with Date on Alpine and Openbsd
Date will work for bash, dash, and sh on Freebsd.
However it will not work for ksh on Openbsd, or for busybox on Alpine.
41
With busybox on Alpine, it simply ignores the %N format specifier and prints out the epoch in seconds only followed by the decimal separator.
=
Example
date '+%s.%N'
1779634800.
42
With ksh on Openbsd it prints the epoch in seconds followed by the decimal separator and then the %N as a literal N.
date '+%s.%N'
1779634800.N
43
Fortunately we have alternatives for these two cases.
--------------------
44 Openbsd
Openbsd has the "ts" or timestamp utility installed by default.
ts prints a time stamp in front of every line it receives from standard input.
I won't go into details on all aspects of ts here, I'll leave that to someone else.
Instead I will focus on how to use it for our specific purposes here.
45
We need to provide a format specifier to ts, which in this case is "%.s"
We also need to provide something for standard input, or otherwise ts will simply sit there and wait for input.
So what we need to do is to echo nothing through a pipe to ts while also giving ts the proper format specifier.
46
Example
echo | ts "%.s"
47
This will output the epoch time in seconds to six decimals of precision.
ts is installed in Openbsd and Freebsd by default and can be used in either.
It can also be installed in many other distros.
--------------------
48 Busybox on Alpine
None of the methods discussed so far will work for busybox on Alpine though.
However there is a way, but it's a bit non obvious and somewhat hacky.
49
Busybox includes a command called "adjtimex".
This is normally used to adjust the time hardware.
However if it is run without arguments, it will report the current settings.
50
These include the current epoch time in seconds , and in another field the time in microseconds.
These are reported as key value pairs.
So what we need to do is to do the following
51
Run adjtimex
Capture the output.
Grep for "time.tv_sec"
Grep for "time.tv_usec"
Use cut to extract the time value in each case.
Use tr to get rid of excess spaces in each case.
Combine the two in a string with a decimal separator between them.
52
This takes a total of 4 lines of shell script.
I will just describe them breifly here, see the show notes for details.
53
First we want to capture the output of adjtimex in a single operation.
Run adjtimex and pipe the output through grep to capture lines containing "time.tv_"
and save this to a variable.
# Extract the current high resolution time from adjtimex.
# We want two key value pairs, identified by time.tv_sec and time.tv_usec.
tvals=$( adjtimex | grep "time.tv_" )
54
Next echo the contents of this variable and pipe it through grep, cut, and tr to get first the seconds and then the microseconds while also removing excess spaces.
Save these to two separate variables.
"time.tv_sec" is the time in seconds since the epoch.
"time.tv_usec" is the number of microseconds in the current second.
# Get the time since the unix epoch in seconds and micro-seconds.
timesec=$( echo "$tvals" | grep "time.tv_sec" | cut -d: -f2 | tr -d " " )
timeusec=$( echo "$tvals" | grep "time.tv_usec" | cut -d: -f2 | tr -d " " )
55
Adjtimex does not zero pad the microsecond time value to provide leading zeros, so we need to take care of this using printf before we can append it to the seconds value. We didn't need to do this with date where the %N format character does this automatically.
In this instance, the printf format string is '%06d'
padusec=$( printf '%06d' $timeusec )
Now, combine these into a single number with a decimal separator by using simple string concatenation.
# Combine them into a single number.
timehires="$timesec"".""$padusec"
--------------------
56 Summary of Methods
Let's summarize where we are so far in terms of methods we can use to get the current time as a high resolution number.
Alma : use EPOCHREALTIME or date
Debian (bash) : use EPOCHREALTIME or date
Raspberry-Pi (bash) : use EPOCHREALTIME or date
ubuntu2604 (bash) : use EPOCHREALTIME or date
Suse : use EPOCHREALTIME or date
Debian (dash) : use date
Raspberry-Pi (dash) : use date
ubuntu2604 (dash) : use date
Alpine : use adjtimex and parse the output
FreeBSD : use date or ts
OpenBSD : use ts
--------------------
57 Other alternatives
There are a few alternatives that we haven't discussed yet.
58 Bash with Dash
In the case of Debian, Raspberry Pi, and Ubuntu running dash, since bash is available it is possible to write a separate bash script which simply echos EPOCHREALTIME and then call it from the dash script and capture the output.
While this would work, there's probably not a lot of point to it.
If you can rely on bash being there, then just change the first line of the script and make it a bash script.
59 Adding Packages to Alpine
The ts or timestamp utility is a common unix utility that can be installed if it is not present by default.
This does produce high resolution timestamps on Alpine.
On Alpine Linux this comes as part of the "moreutils" package.
To add the package, use the following
sudo apk add moreutils
echo | ts "%.s"
1779634800.959948
60
You can also add the GNU coreutils, which will provide a high resolution date command which works like in the other examples.
To add the package use the following
sudo apk add coreutils
date '+%s.%N'
1779634800.212897332
61
If you can install more packages into your Alpine system, either of the above two is probably going to be preferable to parsing the output of adjtimex.
62 Custom Timestamp Programs
You can also write a very short program in python, perl, tcl, or some other language and have it output the current epoch time.
I won't discuss that here though.
--------------------
63 Calculating Time Differences
Shell arithmetic is integer only.
If we wish to use high resolution timing data, we need to do something so we don't lose the precision we have worked so hard to get.
There are several possible solutions.
64 Change the Time Base
One method is to change the time base from seconds to milli, micro, or nanoseconds.
This can be done by simply multiplying the time values by the appropriate amount (e.g. 1000, 1,000,000, etc.) before subtracting them.
This allows for integer arithmetic on high resolution values without losing precision.
65 Use the Shell bc Arbitrary Precision Calculator
The bc command line calculator will perform calculations using real numbers and is easy to use in scripts.
It is present by default in most distros.
echo "scale=9; $endtime - $starttime" | bc
where endtime and starttime are variables containing time values.
66
However, for some inexplicable reason, neither Debian nor Opensuse install it by default.
It is present in Ubuntu and Raspberry Pi which are Debian derivatives, and it can be added to distros which lack it.
67 Use awk
awk can also perform calculations using real numbers and it is present in nearly all distros including in all of the ones we tested here.
echo "$endtime $starttime" | awk '{printf "%.6f\n", $1 - $2}'
--------------------
68 Benchmarks
And of course no comparative evaluation would be complete without benchmarks where we see how each method compares to another in terms of speed.
In the benchmark test I ran each method in a loop through multiple iterations, measured the elapsed time, subtracted out the time for an empty loop, and then compared it to alternate methods.
For anything other than EPOCHREALTIME, the empty loop time is negligible and has no real effect on the results.
69
Rather interestingly I came across a bug which caused date to run very slowly if called immediately after using EPOCHREALTIME in bash.
The effect of the bug was to make the date benchmark test roughly 24 times slower.
This has been fixed in newer releases, but if you are using an older distro release then beware of this bug.
I was able to get around it either putting a sleep delay between benchmarking EPOCHREALTIME and benchmarking date, or by simply testing date before testing EPOCHREALTIME.
70
To be able to conduct additional tests I installed ts in Ubuntu and Alpine, and the GNU version of date in Alpine.
71 EPOCHREALTIME Versus date in Ubuntu 2604 bash
The EPOCHREALTIME method is 3103 times faster than date.
However, when the same test is run on Ubuntu 2404 when the date test is run before the EPOCHREALTIME test, EPOCHREALTIME is 1240 faster than date.
Other Linux distros show performance to Ubuntu 2404.
It appears that a side effect of fixing whatever the bug is has the effect of slowing down date.
However, this is probably not a significant issue in normal circumstances.
72 date versus ts in Ubuntu 2604 bash
The date method is 3.7 times faster than ts
73 date versus ts in Ubuntu 2604 dash
The date method is 4.9 times faster than ts
74 date versus ts in Freebsd sh
The date method is 2.5 times faster than ts
75 date versus adjtimex in Alpine Busybox
The date method is 6.0 times faster than adjtimex
76 date versus ts in Alpine Busybox
The date method is 20.0 times faster than ts
77 bc versus awk in Ubuntu 2604
I compared calculating the difference between two numbers when using bc versus awk.
The difference is negligible, with bc being only 7% faster than awk.
78 Conclusion for Benchmarks
Based on these results, if you need to measure elapsed time to high resolution and care about runing the command with as little overhead as possible, then the order of preference should be the following.
79
If you are using a newer version of bash, then use EPOCHREALTIME.
If that is not available, then use date, provided it allows for high resolution times.
If the above two cannot be used, then use ts.
If you are using Busybox and cannot install either GNU date or ts, then use adjtimex.
Date is the closest in terms of being the universal portable solution, but it does not work in all cases.
80
I have not compared different platforms to each other in terms of performance, as that would be a much more involved problem that is outside the scope of this episode.
However, different operating systems implement different commands in different ways.
81
For example, on Openbsd and Freebsd, ts appears to be an ELF binary. That is, it is executable machine code, possibly written in C.
On Ubuntu however, ts appears to be a perl script.
As a result of this, the advantage that date has over ts is much less in Freebsd than it is with Ubuntu (and likely other Linux distros) as on Freebsd it doesn't need to load a perl interpreter to run ts.
--------------------
82 Overall Conclusion
You no doubt thought that measuring elapsed time was going to be so simple, and how could someone get an entire podcast out of such a simple subject?
And yet here we are half an hour later with just a basic overview of the subject.
83
I hope you found this interesting and informative.
Please let us know in the comments if you think that I have done anything incorrectly, or if you have another way of doing things.
I hope to see you all again in another future episode of HPR.
--------------------
Provide feedback on this episode.
Flere Nyheder podcasts
Trendige Nyheder podcasts
Om Hacker Public Radio
Hacker Public Radio is an podcast that releases shows every weekday Monday through Friday. Our shows are produced by the community (you) and can be on any topic that are of interest to hackers and hobbyists.
Podcast-webstedLyt til Hacker Public Radio, Stjerner og striber og mange andre podcasts fra hele verden med radio.dk-appen
Hent den gratis radio.dk-app
- Bogmærke stationer og podcasts
- Stream via Wi-Fi eller Bluetooth
- Understøtter Carplay & Android Auto
- Mange andre app-funktioner
Hent den gratis radio.dk-app
- Bogmærke stationer og podcasts
- Stream via Wi-Fi eller Bluetooth
- Understøtter Carplay & Android Auto
- Mange andre app-funktioner

Hacker Public Radio
Scan koden,
download appen,
begynd at lytte.
download appen,
begynd at lytte.
