Top 60 Oracle Blogs

Recent comments

Writing Linux Scripts- Part I

Many see scripting as a science, but if you want to write not just functional scripts, but efficient and easy to work with scripts, it is also an art.

Most SQL DBAs are feeling the pressure to learn BASH as they enter Azure and I strongly recommend it. I’m learning PowerShell as part of my education coming from a Linux background to Azure. It’s all about “the more you know”….you know?

So let’s start with learning it right.

Scripts = Stories

A good script has the following parts to it:

  • An Introduction
  • A Body
  • A Conclusion

We’re going to focus on this as part of our education on Linux scripting before we get into a load of terminology or scripting language.

The Introduction

Just as we would have an introduction to a story, we need to set up our reader for what we plan on performing as part of our script:

  • What scripting language do we plan on using
    • If shell, we’ll set our shell, (#/bin/bash)
    • If we’re working with Python, well then we’ll import our pre-built functions
  • We’ll set up our arguments, our variables and other values that are pertinent to the script processing what is needed dynamically or statically
  • Designate any error handling and requirements for the script to execute.

The Body

This section will contain 90% of the “functional” code. This is the meat of the script- processing, manipulating and building out what must be performed or performing it. The reason that I say perform or what will be performed is that functions are a very powerful and useful part of Linux scripting, allow you to more efficiently build and test your scripts, (as anyone who works with them would verify…) and is a big part of advanced Linux scripting.

The Conclusion

In the conclusion, you will wrap up, clean up, log out or if using functions, execute all the code in your script that you’ve spent so much valuable time on building.

Now that we know what is expected in our scripting quality, we’ll start to break down each piece in subsequent posts.

Keep your chin up!

Tags:  ,





Copyright © DBAKevlar [Writing Linux Scripts- Part I], All Right Reserved. 2019.