draft0 - a shared blog by just some people

Menu

All Entries (Page 27)

Bash script to burn your CPU easily

When making my own CPU cooler or testing some other stuff I sometimes need to create as high of a CPU load as possible. After typing while true; do true; done for the one-too-manyth time I finally decided to create an alias for that. But that didn't feel neat enough. So I made this simple Bash script.


#!/bin/bash

if [ "$#" -ne "1" ]
then
  echo "I need one argument and one argument only: Number of threads to start."
  echo "Hint: You have $(nproc) CPU cores."
  exit 1
fi

if [[ "$1" =~ ^[0-9]+$ ]]
then
  n="$1"
else
  echo "Argument needs to be a number: Number of threads to start."
  echo "Hint: You have $(nproc) CPU cores."
  exit 1
fi

trap "pkill -P $$; exit 0" SIGHUP SIGINT SIGTERM

while [ "$n" -gt 1 ]
do
  while true; do true; done &
  n=$((n-1))
done
echo "Started $1 threads to burn your CPU."
pidof -x "$(basename -- $0)"
while true; do true; done

Download

For a simpler script, you can also just use this three-liner without any arguments to stress all CPU cores:


#!/bin/bash
yeah() { while true; do true; done& }
threads=$(nproc)
for i in $(seq 1 $threads); do yeah; done
Comment via email

I'm drunk. Sorry.

Edit: I hardly remember making this entry. But my guess is that I had a subjectively good reason. So I'm leaving it here even if I don't know what it is referring to. (I don't even know how sorry I was.)

Comment via email

Bash script to quickly open and close a wifi hotspot

I needed a wifi hotspot to test some phones. So I looked up how to create one quickly and learned about nmcli. It wasn't quick and easy enough for my taste. So here is how I do it from now on.

The Bash script maintains only one connection (named quick-hotspot). You can't create multiple connections or access points with it. Not intentionally, but also not accidentally because you forgot that you still have a hotspot enabled from the last time you needed one. (I know I would at some point.)

Examples:


hotspot # Creates and enables a hotspot with a random name and a random 8-digit password.
hotspot down # Disables the hotspot if it was enabled.
hotspot ⊿ⴼͳΞⵖⵡ∃ doctorwho # Creates and enables a hotspot with the SSID "⊿ⴼͳΞⵖⵡ∃" and the password "doctorwho".
hotspot . password # My use case: quick and short and I don't want to type a complicated password on the phones. SSID: ".", PW: "password"
hotspot down # Deactivates the hotspot regardless of the SSID you used.

If you activate a hotspot while one is already active, it just changes the SSID and password so that no two connections created by this script are ever active at the same time. I'm sure there already is a program that solves this better. But it was fun for me to create and I felt like sharing.

Click here to download the bash script.

Content:

#!/bin/bash

# Quickly create and activate a WiFi hotspot - optionally defining SSID and password - and deactivate it again when you don't need it anymore.

usage() {
  echo "Usage: $(basename $0) ssid passphrase"
  echo "       $(basename $0) down"
  echo "       $(basename $0)"
  exit 1
}

activate() {
  # If the connection "quick-hotspot" doesn't already exist...
  if ! nmcli connection show | grep quick-hotspot; then
    # ... then create it.
    nmcli connection add type wifi ifname '*' con-name quick-hotspot autoconnect no ssid "$ssid"
  else
    # ... else change the SSID of the existing connection.
    nmcli connection modify quick-hotspot ssid "$ssid"
  fi
  # Make the connection an access point
  nmcli connection modify quick-hotspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
  # Change the password
  nmcli connection modify quick-hotspot 802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk "$pw"
  # Enable the connection
  nmcli connection up quick-hotspot
}

case $# in
  0)
    ssid=$(</dev/urandom tr -dc A-Z] | head -c8; echo "")
    echo "SSID: $ssid"
    pw=$(shuf -i 10000000-99999999 -n 1) 
    echo "PW: $pw"
    activate
    ;;
  1)
    if [ $1 == down ]; then
      nmcli connection down "quick-hotspot"
      exit 0
    else usage
    fi
    ;;
  2)
    ssid="$1"
    if ! [ ${#2} -ge 8 ]; then
      echo "$(basename $0): Password needs to be 8 characters or longer."
      exit 1
    else
      pw="$2"
      activate
    fi
    ;;
  *)
    usage
    ;;
esac

See also: My Reddit Post

Comment via email

My Atrocities to Vintage Hardware and Software

I've thrown away a lot of stuff over the time that I mourn now. This is just to say: I'm sorry!

I feel bad when I think back and remember some things that I had collected, didn't value back then, but miss now. I had a lot of computer hardware that wasn't worth anything at the time. (Like 386 and 486 stuff in the 2000s.) I'd love to play with some of the stuff today sometimes. I think it was a waste to throw them out knowing that nobody will ever use them again. There was also an IBM PS/1 in good condition. That would be a very nice thing to own for a retro computer fan today. (It already was back then.) I also had years worth of c't magazines that I had a subscription for for a while. I had my reasons. I didn't have room to store so much stuff. But still. Maybe I could have kept just a few more things.

Even worse is that I've thrown away quite a few floppy disks with very rare software. The things I wrote back then are one thing. Nobody has a copy of these programmes I'm sure. The collection of Prologue OS software is another. Prologue was a French UNIX-like (yes, I said UNIX-like) OS for industrial applications. As far as I know there is no successor in development or still supported. It's a piece of computer history that, due to the relatively small regional spread, is not at the forefront of vintage software archives. In fact I've never seen any software for Prologue nor a version of the OS itself anywhere on the internet. The collection contained multiple versions of the OS from I don't know how long of a time span and a range of applications. The source code for many applications was also there (because of a familial connection to the author). At least some of the floppies likely contained the last copy in existence of software that was once very important in the daily work of some people.

I'm sorry!

Comment via email

SBWG 0.8.9

Lately I'm making only slow progress with SBWG. I'm determined to make this something that I'm comfortable with sharing as 1.0.0 online. Something that works and could arguably be called a somewhat finished peace of software. That doesn't mean that the todo list won't be huge at the point I change the version number to 1.0.0. But it should be in a relatively good state for what I've decided it will encompass at version 1.0.0. "Relatively" because it's still also a learning project and I would write many things differently if I started over, which means I'll have to rewrite them at some point to be satisfied with SBWG.

So, the goal and roadmap is set for v0.9.0 and v1.0.0 and a large part of what is still to be done is documentation and other things I don't enjoy doing as much as starting to implement new features. I'm holding back on working on things that are not on that roadmap so that I don't introduce new bugs and the need of further testing. First I want to improve what SBWG can already do.

That means that there won't be many interesting changes in the coming weeks (or maybe even months). Today I've decided to call what I've currently got version 0.8.9 and publish it on the project page.

Comment via email

Useless Memories (Part 2)

Once I woke up from a chaotic dream that wasn't a story but rather a mingling of unrelated and overlapping thoughts. The sort of dream that is often called NREM dream by hobbyists without having measured anything that could give indication of the sleep stage one was in at the time. I woke up very tired, with the realisation that what I had just thought of could be an ingenius idea for a story that, would I choose to invest the necessary effort and time that is required to become an author, could be made into a fabulous novel or movie. It was such a genius idea for a story that I would have been surprised if such a constallation of relationships and events had ever been made into a book or movie script without me having ever heard about it. A really good, new idea. I knew about the phenomenon of waking up with such a feeling with its source in a staggeringly trivial or even completely incoherent idea. People who record their dreams after waking up sometimes take such notes and realise later, when their brain is more awake, that it seems almost impossible that they ever thought this idea could be considered anything more than low effort at constructing a sensible sentence or a statement that at best could be seen as a true statement. So I thought it through before I started to write my idea down. I thought about the story and the key events that I felt were so genius. It really made a lot of sense. I stood up to grab my notebook and a pen. And the idea was gone. I couldn't remember a single thing about it beyond what I have written here so far and the fact that it was somehow based on or inspired by the story of "The Lives of Others" ("Das Leben Der Anderen"). I think I even had great pun as a title. (I like puns.) Sometimes I remember this feeling of disappoinment that I experiences maybe 8 years ago. But I long gave up remembering anything from my story idea or even the title that I had thought of.

Comment via email

Useless Memories (Part 1)

Before I started writing the sentence, I remembered something unrelated, switched the tab in my terminal emulator, fixed a bug, switched back... and now I can't remember what it is that I wanted to write about here. So I just wrote that because it's also related to thoughts and memory.

Comment via email

SBWG update - version 1.0 takes shape slowly

I rarely wrote updates on SBWG before now. I just worked on it whenever I had time and felt like it. And that was quite often. But this is my website where I want to feel fine with pretending that what I'm posting is of any real interest to anybody. So I may post more updates on what I did to approach my goals for SBWG 1.0 from now on. It is rare for me that I invest so much time in a single project. And since I'm starting this blog at the same time and want to fill it with a lot of content, it is time to combine the two.

Some things that I did and changed but didn't report on so far: The header format of entry and page source files has been changed completely (simplified), the generated HTML became more complete, the idea of a sourced settings file came (first to me, then reality), new tag types have been formed, the sorting of blog entries is much more mature now, many more customisation possibilities cropped up and I developed an overall vision of what SBWG will become.

The code grew so much over the time. But it was mostly for very good reasons. I'm feeling overall quite content with how clean the code became and how many contingencies I took into account. It's probably still not "professional" code. But it is a new level of professionalism for me and my Bash scripts. Should I ever come close to getting through all the tiny, small, irrelevant, important, stupid, huge, new and old to-dos, it would probably be quite presentable. So many small features have been added that I hadn't thought of when I startet to write SBWG. Multi-author blogs are supported now, tags can be substituted for icons, a basic RSS feed works, ...

Comment via email
Mastodon