Bash automation for Ubuntu Server

Hello,

I developed Bash scripts to automate the installation and configuration of open-source software (i.e., LinuxHA in Launchpad and LinuxSOHO in Launchpad). I want to make sure the syntax of these scripts is perfect so I can use them as teaching tools to educate people about Ubuntu Server.

I need to know if there is anything misconfigured with my Bash syntax.

If you find a bug in LinuxHA or LinuxSOHO, please submit a bug report.

Kind regards,

Travis Bean

Hi @tbean74 !

The answer is likely Shellcheck, which is installable on your Ubuntu system with a simple apt install shellcheck. Then run it against your code.

shellcheck LinuxHA.sh

For example:

$ shellcheck LinuxHA.sh

In LinuxHA.sh line 98:
if [ $(id | awk '{ print $1 }') != "uid=0(root)" ]; then
     ^------------------------^ SC2046 (warning): Quote this to prevent word splitting.


In LinuxHA.sh line 107:
ping -q -w 1 -c 1 $(ip r | grep default | cut -d' ' -f 3) > /dev/null
                  ^-- SC2046 (warning): Quote this to prevent word splitting.


In LinuxHA.sh line 108:
if [ $? -ne 0 ]; then
     ^-- SC2181 (style): Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.

That’s just the first few lines, there are a few more:

$ shellcheck LinuxHA.sh | grep SC | wc -l
436

You can also add a shellcheck extension to VSCode which can check while you type, and offer solutions.

(by the way, I have moved this post to the support category)

3 Likes

I meant to say, “I need to know if there is anything misconfigured with my Ubuntu Server configuration files.”

For the time being, I removed the most relevant bugs with Shellcheck. I will try to remove the rest of what Shellcheck flags when I have the time.

What I am most concerned about is that every time a new version of Ubuntu Server is released, some of the underlying configuration files change for the software packages I have integrated into my LinuxHA and LinuxSOHO scripts.

It would be nice if there was a program developed that could detect every time the configuration file of a software package changed.

In the meantime, it sure would be nice if people would test my LinuxHA and LinuxSOHO scripts and let me know if anything is misconfigured and broken.

This is scriptable by using git on your /etc directory (and other dirs that carry configs FWIW) … just make an automatic commit every time your system updates and you will have a history of commits you can walk through backwards if needed and check the diffs …