Tools that extend Bash scripting

#!Bash

System Logging

Linux handily locates all system logs in /var/log/, where you can go to look at system messages, login messages, and more. Wouldn't it be nice to put your own messages relevant to the system in /var/log/messages, where system messages are logged? A utility named logger [16] allows you to send messages to the system logs. Although users don't have access to these logs, system administrators can use them to track down problems.

One of the most obvious use cases for logger is to have production scripts enter information into the system log. For example, it could be part of a cron job that finds the used disk space of all users, or it could be used to track user usage. The simple two-line script that follows shows how to use logger to add data to the system logs (Figure 12):

#!/bin/bash
logger "Just finished a job by user jlayton"
logger " Date: `date` "
Figure 12: Output added to /var/log/messages.

Summary

Simple scripting using languages such as Bash are extremely common in an admin's toolkit. Bash is installed with most Linux distributions, it is small in size, and it has few dependencies. Thus, it is an ideal tool for system administrators. However, there are times when Bash doesn't have all the capabilities you want, or you might want to take a script to the next level and include interaction with users.

To achieve this, you might have to install tools that supplement Bash, while adding additional dependencies. Some people might argue that if you are going to add tools (e.g., TUI/GUI) to Bash, you might as well convert to a more complete scripting language, such as Python or Perl. However, these tools can have a much larger footprint than Bash and can create even more external package dependencies. Which way you want to go is up to you, but be aware that Bash can be a very effective scripting tool with just a few additional tools.

This blog represents my own view points and not those of my employer, Amazon Web Services.

The Author

Jeff Layton has been in the HPC business for almost 25 years (starting when he was 4 years old). He can be found lounging around at a nearby Frys enjoying the coffee and waiting for sales.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus