Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

You can then easily play back a voice message by using this script (in this
case named pmm):


Click here to view code image
matthew@seymour:~$ pmm name_of_message


Shell scripts that contain positional parameters are often used for automating
routine and mundane jobs, such as system log report generation, file system
checks, user resource accounting, printer use accounting, and other system,
network, or security administration tasks.


Using a Simple Script to Automate Tasks


You could use a simple script, for example, to examine your system log for
certain keywords. If the script is run via your system’s scheduling table,
/etc/crontab, it can help automate security monitoring. By combining
the output capabilities of existing Linux commands with the language
facilities of the shell, you can quickly build a useful script to perform a task
that normally requires a number of command lines. For example, you can
create a short script, named greplog, like this:


Click here to view code image
#!/bin/sh


name: greplog


use: mail grep of designated log using keyword


version: v.01 08aug02



author: bb



usage: greplog [keyword] [logpathname]



bugs: does not check for correct number of arguments


#   build   report  name    using   keyword search  and date
log_report=/tmp/$1.logreport.`date '+%m%d%y'`

#   build   report  header  with    system  type,   hostname,   date    and time
echo "=============================================================="
\
>$log_report
echo " S Y S T E M O N I T O R L O G" >>$log_report
echo uname -a >>$log_report
echo "Log report for" `hostname -f` "on" `date '+%c'`
>>$log_report
echo "=============================================================="
\
>>$log_report ; echo "" >>$log_report
Free download pdf