Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

CHAPTER 14


Automating Tasks and Shell Scripting


IN THIS CHAPTER


Scheduling  Tasks
Basic Shell Control
Writing and Executing a Shell Script
References

This chapter covers ways to automate tasks on your system by using task


schedulers. This chapter also provides an introduction to the basics of creating
shell scripts, or executable text files written to conform to shell syntax. Shell
scripts run like any other command under Linux and can contain complex
logic or a simple series of Linux command-line instructions. You can also run
other shell scripts from within a shell program. The features and functions for
several Linux shells are discussed in this chapter after a short introduction to
working from the shell command line. You find out how to write and execute
a simple shell program using bash, one of the most popular Linux shells and
the default shell in Ubuntu and most other distributions.


Scheduling Tasks


There are three ways to schedule commands in Ubuntu, all of which work in
different ways. The first is the at command, which specifies a command to
run at a specific time and date relative to today. The second is the batch
command, which is actually a script that redirects you to the at command
with some extra options set so your command runs when the system is quiet.
The last option is the cron daemon, which is the Linux way of executing
tasks at a given time.

Free download pdf