Learning new things every day - octal in the shell

OK - so I wrote a PowerShell script to keep my work RDP sessions from timing out - been using it a while - deciced to make a short cut to launch it (PowerShell is SO SO SO UGLY!) :

Clear-HostEcho “Keep alive w/ scroll lock…”$WShell = New-Object -com “Wscript.Shell”while ($true){$WShell.sendkeys(“{SCROLLLOCK}”)Start-Sleep -Milliseconds 100$WShell.sendkeys(“{SCROLLLOCK}”)Start-Sleep -Seconds 240}

And I got SICK of right clicking on it and “Run with PowerShell” so I created a shortcut :

Target : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "%USERPROFILE%\Desktop\nodoze.ps1", and “Start in” of %USERPROFILE%\DesktopOh so ugly (and I also learned, not that I tried it - but PowerShell can also use tilde “~” to represent “%USERPROFILE%”… SO UGLY… Anyway…

While I was there - decided to write a silly “keep alive” for my SSH sessions to remote hosts - I use MobaXterm on those Windows machines.

In Australia (and pretty sure in the UK too) you could ring a freecall number (it was #1194 in Au) and hear the talking clock man announce “…at the third stroke the time will be $HOUR $MINUTE and $SECONDS” - if it was going to hit a new minute on the third stroke, it would be “…at the third stroke the time will be $HOUR $MINUTE precisely”…

So - anyway - I only learned (today) that bash arithmetic treats numbers with a leading zero as octal - so if you need to convert to decimal you have to prefix 10# on the variable that could potentially be treated as an octal number : TERD=$(( 10#$SS +3 ))

       │ File: talkyclockcrap.bash
   1   │ #!/usr/bin/env bash
   2   │ # the old cruddy talking clock #1194 : 
   3   │ while true
   4   │ do 
   5   │     TIME=$(date '+%H:%M')
   6   │     SS=$(date '+%S')
   7   │     TERD=$(( 10#$SS +3 ))
   8   │     echo "echo at da terd stroke it'll be $TIME($SS) and $TERD seconds approx..."
   9   │     echo -e "pip" ; sleep 1
  10   │     echo -e "\tpip" ; sleep 1
  11   │     echo -e "\t\tpip" ; sleep 1
  12   │     clear
  13   │ done

And yeah - I’m too lazy to change it to correctly calculate where $SS and $TERD are =>57

and yeah - I always write naughty cuss words in my shell scripts :smiley:

And yesterday I learned about $TMOUT variable - even if you’re root, you can’t change it in your current $ENV… I updated /etc/profile.d/timeout.sh - the default value was some UTTER CRAP like 10 minutes! WTF? This is on Red Hat Linux (EL) 8 :

cat /etc/profile.d/timeout.sh
readonly TMOUT=7200
export TMOUT

I think 7200 is two hours - which is pretty reasonable IMHO… but who decided on 10 f–king minutes (not this is not default on REL8 - someone [a colleague?] created a VMware template, and set $TMOUT to 10 minutes)?


I seem to remember BO74 from the days when telephone dials had letters.

You did not allow for the time the echo takes in spacing out the pips with sleeps

Surely not as grave a “crime” as not accommodating for seconds =>57 (and thereby not accomodating “precisely”).

I remember my grandparents had a huge “long” black bakelite phone on their semi-rural propery in the Hunter Valley (Wallsend) - where my grandpa ran both a chook (Aussie for poultry) farm, and his plumbing / earthmoving business - he also had time for a cow at the bottom of his chook farm - and he’d drop by our house in inner city Newcastle with a flagon (which he’d scored off us as my dad was fond of wine by the flagon) of unpasteurized milk (he was a health nut, and believed pasteurization of dairy was “evil”). I’ve heard horror stories of people dying in Australia from consuming unpasteurized (reminds me of an Aussie colloquialism pasteurize = “past your eyes and down your throat”) dairy foods - probably left it too long and it spoiled…

Anyway - I digressed too far - my grandparent’s phone had a rotary dial on it, but also a bunch of buttons - maybe something like this - except it also had a rotary dial :

Where they lived was semi-rural, Wallsend being mostly a town, some farms, and a whole bunch of coal mines - of course - it’s all built up now, just a suburb of greater Newcastle…

1 Like