Scripting for a non-coder (How to start)

As non-coders it can be a difficult process to automate routine tasks. What things can we do as non-coders to allow us to automate our jobs as well as growing our skills in the automating process? There are a few things I have done over the years to help my productivity with not much more than reading articles on the internet. I have no formal coding background; most of my skills have been self-taught.

One of the most beneficial things I have done to allow me to start automating, as well as helping my skills to grow, is keeping a log of one-line scripts and documenting output, as well as what I am trying to accomplish. For example, I wanted to do a “server alive” script that notifies when there is an issue. I would use a command line utility program to run ping to display the correct output I was looking for. Sometimes you will have to read documentation on the different options to get your desired results. I would document the command, output, and what I was trying to achieve. In the output, what data am I looking for? What gives me the desired knowledge that the system is live on the network? I would also compare a successful check with what a failure looks like, in order to determine what data is needed to be collected to differentiate between the two results.

The next steps change based on your skill set. You may want to consult the internet or previous one-liner examples. You want to take your output from one command and redirect into some other command that would allow you to validate the results to be true or false, based on what was determined from your output in the previous step. For example, your ping output should generate a line with “TTL” which represents success. You would need some sort of command that would determine that your output had the desired result.  At this point, you can search on the internet for the right command in the language of your choice, and you’ll get examples from other people which will help you to develop your scripts to get your desired results.

Once you have created the small script of one-liners, you will be able to work on putting them together in some sort of condition statement to validate success or failure. In most scripting languages you would be looking for “if then or else” statements. I would start with working in steps. From the ping command, I would redirect the output to another command that would try matching it to a desired result in order to give confirmation of success or failure.  Then do the same for a failed result just to make sure there are no false positive. Now you have two steps that work. What next? Do you just want it to send the data to a log file or send notification based on results? I would start with sending your data to a log file so you can audit results until you are ready for the process to be fully automated. As a new scripter you will want to validate time and time again for any mistakes with your results. Don’t take your first pass as your final results. There can always be a condition you never thought of. This is one reason that I continually update my one-liner and function documentation.

The next big starting point is learning how to put each one of your small scripts into functions or sub routines. This will allow you to call small chunks of code to only do one small function. As a part of your functions repository, you are now able to add that section into any future script. This allows for you to speed up your script writing and ability to make the code better as time goes.

In summary, I find the internet a great source for looking for help with simple code/function within your code. It is also a great way to learn other ways to process the same results. With these results you will learn more about your system and application, and most importantly you will save time on many repetitive tasks to allow more time to learn better scripting.