[colug-432] First script - would anyone care to review?
Stephen Potter
spp at unixsa.net
Thu Jun 4 21:16:39 EDT 2015
Zach-
Overall, this looks like fairly clean code. I do, however, see a lot of
code duplication that could lead to typos or forgetting to update a
particular section during script maintenance. For example, not that
this currently affects the script, look at the difference between lines
25, 39, and 46. You have used double quotes in one case and single
quotes in the others.
From an efficiency standpoint, I also see several places where you run
the same command multiple times to get different information each time,
where you might be able to tighten it up and only do it once. However,
in this day and age with the speed of systems, this kind of efficiency
may no longer be something to be concerned about.
From an output perspective, if you have more than one of a particular
network interface (eth0, eth1, for example), your output doesn't readily
identify which one works or doesn't work, which makes troubleshooting a
bit more difficult. Again, with the types of systems you are probably
running this on, it probably doesn't significantly affect you, but it is
something to think about as you develop more complex scripts with
additional inputs and outputs. You might want to include $netw in your
output to identify the interfaces.
I do see one particular error in the host networking case script. Line
26 is attempting to cut information from a string, but the cut command
takes a file as input. To get this to work (you don't actually use it,
because you have the lines that use it commented out), you would need to
do an "echo $netw | cut".
An interesting thing you might want to look into to bring your scripting
to the next level. You have a couple of places where you do several
echo statements that append to a file (lines 124-131 and 148-150, for
example). You could make these a little easier to read (and save
yourself some keystrokes, which are always prone to typos) if you use
"cat" and a "heredoc", like:
cat <<EndofLdapConf >> /etc/openldap/ldap.conf
URI ldap://instructor.example.com
BASE dc=example,dc=true
TLS_REQUIRE allow
EndofLdapConf
-spp
On 6/2/2015 4:49 PM, Zach Villers wrote:
> I'm studying for the RHCSA cert and wanted to create an environment to
> practice on in a virtual machine. I also wanted to learn scripting.
> I'd read a good bit about the absence of good documentation on setting
> up an LDAP server in CentOS/RHEL 7. (In fact the RHEL docs just link
> to a rather unhelpful page on using Mozilla NSS to create TLS
> certificates) I decided to give it a try...a couple weeks ago...there
> is now a dent in my desk from banging my forehead into it.
More information about the colug-432
mailing list