Have you ever been frustrated by that script that just did not work? Are you tired of searching the web for a ready-made script, hoping that it will fix your problem? Want to sit back and relax for a couple of seconds while your script performs the task that would have taken you two hours to accomplish manually? Then you have come to the right course!
This course will help you build your own scripts and understand the ones written by others. No more relying on scripts that others built and hoping that they will solve your custom problems. Just writing your own solutions to your own problems.
Take this course to get:
In short, you will learn the basic building blocks of bash, watch how a real-life utility is built, do the monthly challenges and solve coding problems in the discussion area to gain experience (did I mention the prizes?).
The first section covers basic building blocks that allow you to write your own shell scripts, which are presented in a learn-by-example fashion. Here you will learn about basic linux command line utilities used throughout the course, a simple script structure, defining functions, using input/output redirection, pipes and command substitution. The last lectures in this section focus on control statements, like if, case, while and for.
In the second section I will show you how to build a simple real-life utility for monitoring the amount of traffic on a network interface. There are two scripts involved in this utility. The "core", that queries system data about a network interface and adds it to a comma-separated-values (csv) file, one line at a time. The other one will take care of scheduling the "core" to be run at specific times, based on a user specified interval. The result is a csv file that contains data collected at specific points in time, data that can be later processed into a spreadsheet application (e.g. build graphs from it).
The rest of the course, what I call the dynamic part, is built in time. You will find here lectures on various command line utilities (e.g. find) or more in-depth lectures on subjects like redirection. I also post monthly challenges for you to gain some much needed experience, in order to ascend from a beginner to an intermediate level.
**** Monthly challenges (with prizes) ****
Jun '16: Utility to count the occurrences of a letter inside a text file
Mar '16: Textify, an utility that takes an integer number and converts it to text
Jan '16: Utility to equally space lines in a text file
Dec '15: Host ping reply time monitor
May 22nd 2016: Published solution for the January challenge
Feb 29th 2016: Published solution for the December challenge
Jan 3rd 2016: New lecture on xargs
Nov 22nd 2015: New section on standard end error output redirection
Nov 15th 2015: New lectures on the find utility and the proc filesystem.
Oct 10th 2015: New quiz on parameters
This lecture briefly describes the utilities used throughout the course and shows you some basic uses.
Going over the basic script structure, how to write comments, define and call functions.
This lecture shows you how to define and use variables.
Arguments are the way a script receives data from the outside world. This lecture goes over how you can access parameter values and manipulate them.
A quick quiz on script arguments.
This lectures teaches you how to write output to a file, instead of the screen; and how to read input from a file, instead of the keyboard.
Pipes are a very powerful feature of the shell. This lecture shows you how to use them.
The fun part of using bash begins with command substitution. In this lecture you are going to learn how to replace a command name with its output.
This lecture covers the 'if' statement and the syntax of the associated condition.
To avoid using multiple if/else if/else statements, use the 'case' statement, that matches an input expression to one of the given patterns.
This lecture covers the while/until loops.
Both forms of the 'for' loops, C-like and lists, are described in this lecture.
This document describes the ifMonitor project goals.
This is the first lecture on the check_iface script, the "core" of the ifMonitor project. This first part shows you how to parse the command line parameters of the script.
In this second lecture on the check_iface script, one line of data is written to the output file.
cron & crontab are used to schedule tasks at a specified time.
Using crontab to schedule the check_iface script.
Short overview on the proc filesystem. We will use files under this folder for the next lectures.
This lecture is about find and gives you an example of how to use it to search for files.
Explanation for the question in the previous quiz.
You should check the find (man find) documentation for the following quiz
xargs - an utility that lets you call other commands with parameters determined at runtime (as outputs of other commands)
A few questions on xargs
Find out how to redirect normal output and errors to different files... or even to the same one.
Quick question about standard and error output redirection.
General challenge rules
Build an application that monitors the ping response time of several hosts.
Build a small tool that equally spaces lines in a file.
Create a simple script that counts the occurrences of a letter inside a text file.
Check the bash manual (man bash) - the Parameter Expansion section - on how to find the length of a variable or how to get a substring (even of length one) from a word.
This lecture will show you how to resolve the host monitor challenge. Besides that, you will take a quick look at getopt, check out a faster way to schedule recurring tasks using crontab and find out how to use the last command error status ($?).
You can download the scripts for this challenge, they are attached to this lecture.
Solving the file spacer challenge. This lecture will give you a quick insight into the workings of the IFS builtin variable.
Hello! I am a passionate software engineer working mostly in the embedded networking world. I have a degree in Computer Science from the Politechnica University in Bucharest, major in Compilers and Operating Systems and have recently obtained an Android Developer Nanodegree from Udacity.
I have been an embedded software engineer for the past 12+ years, developing and maintaining software for a range of Ethernet devices. During this time I have been responsible for various parts of these systems, ranging from the higher levels of networking protocols like VLAN, STP, SNMP to chip drivers and distributed programming across Ethernet switches. At some point I started leading software releases and did a partial shift to project management, while still maintaining a keen interest in the embedded software practice. In the past few years I have added Android and Arduino on my list of interests and I am now working on a small pet project related to air quality, tying these two platforms together.
I usually prefer learning by example. So, it is only natural that this becomes my preferred way of teaching as well. My lectures are filled with examples that illustrate the main presented concept or topic.
I'm looking forward to seeing you in my courses!