line command code

Shell: A Sysadmin’s Basic Tutorial

The Shell… A cloudy mystery for the novice, but an indispensable tool for any seasoned administrator. It is the underlying foundation in any operating system, and if used to its maximum potential, can be extremely effective.

You might be wondering, why is the command line considered useful? cPanel has almost every function you’d need for hosting integrated into a web panel, and Operating systems like Windows are built around a user interface being the primary form of interaction. As a sysadmin, sometimes the issues we face are much deeper than a GUI can allow us to troubleshoot. Other times we simply wish to automate certain functions of our daily routine.

Basic Command Line Utilities

Explored will be a few command line utilities that make our lives easier, along with examples of how we might script certain tasks. Automating some of our daily checks and our more mundane duties frees us up to focus on the more difficult issues we might face.

One of the best functions for the linux command line is the ability to easily string commands together on a single line, sending the output of one command into the next. This comes in handy when searching for a file or when trying to alter the output of a command.

command | awk (arguments) | grep (arguments)

In the above example, the base command is piped (i.e. output is sent) into awk, which alters the data , then its altered output is sent to grep, which searches for a specific keyword within that already-modified data.

While this works perfectly fine, what if we deem that the new output of the linked commands is useful in our daily routine? Sure, we could type out the entire command every time, but why do that if we can make our own command out of it. Some of these piped together commands can become long and tedious to type out every time:

df -h | awk ‘{print substr($5, 1, length($5)-1)}’ | awk ‘NR>1’

Let’s put that string of linked commands into a bash script, name it something memorable, and then put that script into /usr/bin on our linux system.

We can now use our script by just typing what we named it:


On the other end of the spectrum, we have Windows. Modern versions of Windows include two types of shells, the standard command prompt we all know, and Powershell.

As a quick history lesson, command prompt has been around for a long time. Its functionality is built on that of the original DOS operating system. While it serves as a decent shell, it isn’t very useful for scripting and lacks functionality compared to linux bash. In response to this, Microsoft created Powershell. As the name implies, it is a much more powerful shell, designed to be highly flexible and scriptable.

Without Powershell, Windows is limited to only basic batch scripts. Unlike Linux, Windows doesn’t have the ability to easily send the output of one command into another. At most, the output of a command can be sent to a file, or multiple commands ran at the same time using &&:

ipconfig > networkconfig.txt
ipconfig && echo “hi”

In order to perform more complex functions, we would have to resort to using Powershell.

Another big part of what we do is monitoring servers and their health. Most of the time, this is done through having an another server to act as a monitoring server. In some cases where we might need specific statistics, a quick script to run a few commands and email to output to us does the trick. We’re able to customize the output to exactly what we’re looking for, rather than being limited to what a pre-defined command can give us.

Having this flexibility allows us to decide whether we want to see an output such as this:

———-Storage Space———-

Filesystem Size Used Avail Use% Mounted on
udev 12G 0 12G 0% /dev
tmpfs 2.4G 240M 2.2G 10% /run
/dev/mapper/pve-root 94G 7.1G 83G 8% /
tmpfs 12G 34M 12G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 12G 0 12G 0% /sys/fs/cgroup
/dev/fuse 30M 16K 30M 1% /etc/pve
gluster1:stor1 80G 33M 80G 1% /mnt/pve/GlusterStorage
tmpfs 2.4G 0 2.4G 0% /run/user/0

Or an output like this:

———-Storage Space———-

All Volumes Below 80% Utilization

As sysadmins, we monitor, maintain, and configure many systems. The ability to script tasks allows us to shift our focus to more important tasks, and complete more of those tasks in less time.


Not something you’re quite ready to delve into? Learn more about how GigeNET’s sysadmins can make your life easier or  chat with our specialists.