« Previous 1 2
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` "
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.
Infos
- Bash: https://en.wikipedia.org/wiki/Bash_(Unix_shell)
- TUI: https://en.wikipedia.org/wiki/Text-based_user_interface
- tput: https://en.wikipedia.org/wiki/Tput
- curses: https://en.wikipedia.org/wiki/Curses_(programming_library)
- TUI dialog boxes: https://bash.cyberciti.biz/guide/Bash_display_dialog_boxes
- dialog man page: http://linux.die.net/man/1/dialog
- dialog history: http://invisible-island.net/dialog/
- Whiptail: https://linux.die.net/man/1/whiptail
- Xdialog-dialog compatibility: http://xdialog.free.fr/doc/compatibility.html
- Xdialog: http://xdialog.free.fr/
- zenity: https://help.gnome.org/users/zenity/stable/
- kdialog boxes: https://techbase.kde.org/Development/Tutorials/Shell_Scripting_with_KDE_Dialogs
- gnuplot: http://gnuplot.sourceforge.net
- matplotlib: http://matplotlib.org
- bashplotlib: https://github.com/glamp/bashplotlib
- logger: https://linux.die.net/man/1/logger
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy ADMIN Magazine
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Most Popular
Support Our Work
ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.