Does anyone else ever take something simple and over complicate it?
BlackBloodRum Sep 15, 2022
Hey,

Just thought I'd give you guys a laugh!

I decided "Hey, I'm going to update the motd notice updater for my systems". The original idea was that on RH based systems I wanted the MOTD file to contain the currently booted kernel information

So the old script I made a well over a year ago was super simple:

 
#!/bin/bash
echo -e "`cat /etc/redhat-release; uname -a`

KVM Instance  : (hand written name)
IPv4          : (hand written ip)
IPv4 VPN      : (hand written ip)
IPv6          : (hand written ip)
Hostname      : (hand written host)
Administrator : (hand written me contact name and email)
" > /etc/motd


And had a simple systemd unit to execute it on each boot:

 
[Unit]
Description=Update MOTD with system information

[Service]
ExecStart=/opt/motd.sh

[Install]
WantedBy=multi-user.target


Short simple and did the job right? Simples, I just put that on each RH system and done.

Well I was looking at it while checking system files/config and thought.. well what if I change this, maybe that too and oh this too. For example, hey maybe I can make it work with debian with a single script too? etc.

And it kind of exploded into this

 
#!/bin/bash
#
# A simple utility to ensure the correct information is provided
# via motd when logging in.

# Load configuration file
configFile="/opt/motd.conf"
motdFile="/etc/motd"

if test -f "$configFile"; then
  source $configFile
else
  echo "ABORT! Missing config file!"
  exit 1
fi

if [ ${enabled} == "true" ]; then
  if [ ${server_type} == "host" ]; then
    stype="Server        :"
  elif [ ${server_type} == "guest" ]; then
    shost="KVM Host      :"
    stype="KVM Instance  :"
  elif [ ${server_type} == "cloud" ]; then
    shost="Cloud Service :"
    stype="Cloud ID      :"
  else
    stype="Unknown Type  :"
  fi

  if [ ${dynamic} == "true" ]; then
    echo -e `cat /etc/redhat-release` > ${motdFile}
    echo -e `uname -a` >> ${motdFile}
    echo >> ${motdFile}
  else
    echo > ${motdFile}
  fi

  echo "System Details" >> ${motdFile}
  echo "   ${stype} ${server_name}" >> ${motdFile}

  if [ -n "${shost}" ]; then
    echo "   ${shost} ${server_host}" >> ${motdFile}
  fi

  echo "   Hostname      : ${server_hostname}" >> ${motdFile}
  echo -e "   Last Boot     : `date`" >> ${motdFile}
  echo >> ${motdFile}
  echo "Network Details" >> ${motdFile}
  echo "   Public IPv4   : ${server_ipv4}" >> ${motdFile}

  if [ -n "${server_additional_ipv4}" ]; then
    for ipv4 in ${server_additional_ipv4[@]}; do
      echo "                 : ${ipv4}" >> ${motdFile}
    done
  fi

  if [ -n "${server_ipv4_vpn}" ]; then
    echo "   Private IPv4  : ${server_ipv4_vpn}" >> ${motdFile}

    if [ -n "${server_additional_ipv4_vpn}" ]; then
      for ipv4vpn in ${server_additional_ipv4_vpn[@]}; do
        echo "                 : ${ipv4vpn}" >> ${motdFile}
      done
    fi
  fi

  if [ -n "${server_ipv6}" ]; then
    echo "   Public IPv6   : ${server_ipv6}" >> ${motdFile}

    if [ -n "${server_additional_ipv6}" ]; then
      for ipv6 in ${server_additional_ipv6[@]}; do
        echo "                 : ${ipv6}" >> ${motdFile}
      done
    fi
  fi

  if [ -n "${server_ipv6_vpn}" ]; then
    echo "   Private IPv6  : ${server_ipv6_vpn}" >> ${motdFile}

    if [ -n "${server_additional_ipv6_vpn}" ]; then
      for ipv6vpn in ${server_additional_ipv6_vpn[@]}; do
        echo "                 : ${ipv6vpn}" >> ${motdFile}
      done
    fi
  fi

  echo >> ${motdFile}
  echo "Contact Details" >> ${motdFile}
  echo "   Administrator : ${server_admin}" >> ${motdFile}

  echo >> ${motdFile}
fi


and a config file to go with it, which is still manually configured to ensure correct info..

 
#!/bin/bash
#
# Configuration for the motd utility
#

# Enable on this system?
enabled=true

# Dynamic uname?
dynamic=true

# Server Type
# - Either "host", "guest" or "cloud"
server_type="guest"

# System Details
server_name=""
server_host=""
server_hostname=""

# Admin Details
server_admin=""

# System connection information
server_ipv4=""
server_ipv4_vpn=""
server_ipv6=""
server_ipv6_vpn=""
server_additional_ipv4=("ip1/32" "ip2/29" "etc")
server_additional_ipv4_vpn=("") # leave as "" to omit
server_additional_ipv6=("")
server_additional_ipv6_vpn=("")


The resulting output in MOTD:

 
Red Hat Enterprise Linux release 9.0 (Plow)
Linux (hostname) 5.14.0-70.22.1.el9_0.x86_64 #1 SMP PREEMPT Tue Aug 2 10:02:12 EDT 2022 x86_64 x86_64 x86_64 GNU/Linux

System Details
   KVM Host      : (configured option)
   KVM Instance  : (configured option)
   Hostname      : (configured option)
   Last Boot     : Tue 13 Sep 01:06:45 BST 2022

Network Details
   Public IPv4   : (configured option)
   Private IPv4  : (configured option)

Contact Details
   Administrator : (configured option)

Last login: Wed Sep 14 16:45:10 2022 from 10.66.6.2


Although.. the systemd unit file stayed the same, so that's something right?

But yeah.. what's wrong with me? It was simple and worked before.. and now it's a whole script to maintain

Thankfully it did stay simple.. but that's still a lot of lines of scripting just to print a couple of details

On the plus side, I achieved my goal of adding debian support (disable dynamic, because debian already prints that info by default)

Do you ever get the feeling of "why didn't I just leave it alone?"

Last edited by BlackBloodRum on 15 September 2022 at 5:25 am UTC
Pengling Sep 15, 2022
Quoting: BlackBloodRumAnd it kind of exploded into this
Exploded is the right word! How did it end up with the script and the config file both being bigger than the actual output?
StoneColdSpider Sep 16, 2022
Quoting: BlackBloodRumDo you ever get the feeling of "why didn't I just leave it alone?"
When I got lumbered into running the golf club website.......

"Oh you work in IT??? Then you can run the website..... Here you go"

Turns out they never had a website....... It didnt exsist.......... long story short....... I had to learn all about websites and I had to build the entire website from scratch........

I should have played dumb and said I didnt know anything about websites......... But the old bastards at the club think that IT is IT and if you know one area in IT you know them all.........

Thankfully I dont play golf anymore and the website is someone elses problem now!!!

From then on I dont tell anyone around where I live what I do for a living...... Everytime people know you work in IT you always get lumbered into doing something.........
BlackBloodRum Sep 16, 2022
Quoting: Pengling
Quoting: BlackBloodRumAnd it kind of exploded into this
Exploded is the right word! How did it end up with the script and the config file both being bigger than the actual output?
Yup!

Well mostly because of the configuration file, ironically enough. This is because the script now has to check for configuration options and act accordingly

The good news is, the script can just be put in place and I edit the configuration file on a per-system basis but still it's a lot of code to just inject a few lines of text

Quoting: StoneColdSpiderWhen I got lumbered into running the golf club website.......

"Oh you work in IT??? Then you can run the website..... Here you go"

Just got a picture in my head of a group of aussies drunk on a beach playing golf around their barbecue and a laid-back kangaroo sitting on a beach chair drinking beer

Quoting: StoneColdSpiderTurns out they never had a website....... It didnt exsist.......... long story short....... I had to learn all about websites and I had to build the entire website from scratch........

I should have played dumb and said I didnt know anything about websites......... But the old bastards at the club think that IT is IT and if you know one area in IT you know them all.........

Thankfully I dont play golf anymore and the website is someone elses problem now!!!

From then on I dont tell anyone around where I live what I do for a living...... Everytime people know you work in IT you always get lumbered into doing something.........

This has happened to me far too many times!

My go-to answer these days when someone new asks me about computers is "Honestly, I have no idea. Give me a computer I barely know how to turn it on! I'm full on computer illiterate"

Once I say this, I never get a "can you just look at this?" or "Any ideas about this problem?" questions or "Hey my laptop is throwing all these errors after I was looking at a web.. - What kind of website? - Oh, just normal ones like facebook you know! - uh huh, sure."

Or "I disabled my antivirus because it was stopping me installing a program I downloaded online, but now I can't get my computer to work right, any ideas what the problem is? - PEBKAC - What? - Oh nothing! Don't disable your antivirus!"

It's much easier now without lots of computer questions being thrown at me every time I mention the word "computer".

Rule #1 of Computer Club, Don't talk about Computer Club.

Last edited by BlackBloodRum on 16 September 2022 at 2:32 pm UTC
Pengling Sep 16, 2022
Quoting: StoneColdSpiderWhen I got lumbered into running the golf club website.......

"Oh you work in IT??? Then you can run the website..... Here you go"

Turns out they never had a website....... It didnt exsist.......... long story short....... I had to learn all about websites and I had to build the entire website from scratch........

I should have played dumb and said I didnt know anything about websites......... But the old bastards at the club think that IT is IT and if you know one area in IT you know them all.........

Thankfully I dont play golf anymore and the website is someone elses problem now!!!

From then on I dont tell anyone around where I live what I do for a living...... Everytime people know you work in IT you always get lumbered into doing something.........
Quoting: BlackBloodRumThis has happened to me far too many times!

My go-to answer these days when someone new asks me about computers is "Honestly, I have no idea. Give me a computer I barely know how to turn it on! I'm full on computer illiterate"

Once I say this, I never get a "can you just look at this?" or "Any ideas about this problem?" questions or "Hey my laptop is throwing all these errors after I was looking at a web.. - What kind of website? - Oh, just normal ones like facebook you know! - uh huh, sure."

Or "I disabled my antivirus because it was stopping me installing a program I downloaded online, but now I can't get my computer to work right, any ideas what the problem is? - PEBKAC - What? - Oh nothing! Don't disable your antivirus!"

It's much easier now without lots of computer questions being thrown at me every time I mention the word "computer".

Rule #1 of Computer Club, Don't talk about Computer Club.
Ain't that the truth! Something like this happened to me courtesy of an older relative, several years ago;

"Pengling, you should make an app!",
"Nah - I don't know how. You can't just 'make' an app - you have to know how to program computers.",
"But it's for a phone - you can just make it!",
"Phones these days are basically computers in a different casing, and I can't make it because I'm not a programmer.",
"But there was this kid in the paper who made an app and he made a load of money out of it!",
"He knows how to program computers.",
"But you should make an app!",
"Why don't you 'make' an app, then?",
"I don't know how - I don't know about computers!".



Last edited by Pengling on 16 September 2022 at 9:36 pm UTC
denyasis Sep 16, 2022
Quoting: BlackBloodRumOnce I say this, I never get a "can you just look at this?" or "Any ideas about this problem?" questions or "Hey my laptop is throwing all these errors after I was looking at a web.. - What kind of website? - Oh, just normal ones like facebook you know! - uh huh, sure.

100% this. It doesn't matter if you're even in IT. I clean streets. I helped my boss copy his email to a new computer (he never deleted an email... For 30 years... Outlook struggled). A few years later he got promoted. Guess who got offered an "inside" job because "your amazing with computers and you help out the guys in the field" (I knew how to manually reboot the onboard computers on some of our equipment when they froze).

Now apparently I'm a SQL database and GIS analyst! Take that you people with degrees and training and industry credentials!! Lol.
StoneColdSpider Sep 17, 2022
Quoting: BlackBloodRumThis has happened to me far too many times!

My go-to answer these days when someone new asks me about computers is "Honestly, I have no idea. Give me a computer I barely know how to turn it on! I'm full on computer illiterate"
When people around where I live ask what I do for a living now I just tell them im an Undertaker........ I have never had a follow up question....... Ever.......
kokoko3k Dec 28, 2022
Sometimes one code just for the fun of it, sometimes one do it to achieve something else.
So I guess overengineering can be useful in the first case, at least :)
While you're here, please consider supporting GamingOnLinux on:

Reward Tiers: Patreon. Plain Donations: PayPal.

This ensures all of our main content remains totally free for everyone! Patreon supporters can also remove all adverts and sponsors! Supporting us helps bring good, fresh content. Without your continued support, we simply could not continue!

You can find even more ways to support us on this dedicated page any time. If you already are, thank you!
Login / Register


Or login with...
Sign in with Steam Sign in with Google
Social logins require cookies to stay logged in.