Title: Create Custom Scripts
Course: CIS 208: Linux/UNIX III: Intermediate System Administration, Networking, and Security ~ For IGNITE Review > Section: Learning Modules

Create Custom Scripts

When managing several user resources, it is most convenient to create a master script which can be run from a cronjob.  This script will find the scripts for individual tests and append their output into a log file.

Here is a sample script which can be customized as needed.

#!/bin/sh
# @(#) blapp   baseline logger app

mkdir -p /var/log/blapp /usr/share/blapp
cd /var/log/blapp

for Script in 'is /usr/share/blapp'; do
Name-'basename $Script'
echo "'date + %F\ %T'": "' /usr/bin/time -f %E $Script &>/dev/null'" >> $Name
done

The script named blapp can be set to run on a cronjob, perhaps 10 minutes after the hour.

10 * * * * /usr/local/sbin/blapp

Now individual scripts can be added to /usr/share/blapp.  Whatever name is given to a script will be the name of the log file in /var/log/blapp.  Notice that will ignore all output from these scripts and it only considers the time of execution.  Test and verify that the scripts actually perform the desired action.

Here is an example script to test DNS resolution for the Google website.

#1 /bin/sh
# @(#) resolve-google      resolves google.com

host google.com

Another example script to open the Google website.

#1/bin/sh
# @(#) open-google      opens google.com

wget -O /dev/null http://www.google.com

Note that the log files could grow to a large size over time.  Either write a script to rotate the log files or configure the logrotate service.