initial commit

This commit is contained in:
Fabio Scotto di Santolo
2020-07-28 19:28:25 +02:00
commit 4cc88d2f6e
245 changed files with 22820 additions and 0 deletions

121
chapter19/iostat_loadmon.bash Executable file
View File

@@ -0,0 +1,121 @@
#!/bin/bash
#
# SCRIPT: iostat_loadmon.bash
# AUTHOR: Randy Michael
# DATE: 12/20/2007
# REV: 1.0.P
# PLATFORM: AIX, HP-UX, Linux, OpenBSD, and Solaris
#
# PURPOSE: This shell script take two samples of the CPU
# usage using the command. The first set of
# data is an average since the last system reboot. The
# second set of data is an average over the sampling
# period, or $INTERVAL. The result of the data acquired
# during the sampling period is shown to the user based
# on the UNIX operating system that this shell script is
# executing on. Different UNIX flavors have differing
# outputs and the fields vary too.
#
# REV LIST:
#
#
# set -n # Uncomment to check the script syntax without any execution
# set -x # Uncomment to debug this shell script
#
###################################################
############# DEFINE VARIABLES HERE ###############
###################################################
SECS=300 # Defines the number of seconds for each sample
INTERVAL=2 # Defines the total number of sampling intervals
STATCOUNT=0 # Initializes a loop counter to 0, zero
OS=$(uname) # Defines the UNIX flavor
###################################################
##### SET UP THE ENVIRONMENT FOR EACH OS HERE ######
###################################################
# These "F-numbers" point to the correct field in the
# command output for each UNIX flavor.
case $OS in
AIX|HP-UX) SWITCH='-t'
F1=3
F2=4
F3=5
F4=6
echo -e "\nThe Operating System is $OS\n"
;;
Linux) SWITCH='-c'
F1=1
F2=3
F3=4
F4=6
echo -e "\nThe Operating System is $OS\n"
;;
SunOS) SWITCH='-c'
F1=1
F2=2
F3=3
F4=4
echo -e "\nThe Operating System is $OS\n"
;;
OpenBSD) SWITCH='-C'
F1=1
F2=2
F3=3
F4=5
echo -e "\nThe Operating System is $OS\n"
;;
*) echo -e "\nERROR: $OS is not a supported operating system\n"
echo -e "\n\t...EXITING...\n"
exit 1
;;
esac
###################################################
######## BEGIN GATHERING STATISTICS HERE ##########
###################################################
echo -e "Gathering CPU Statistics using vmstat...\n"
echo "There are $INTERVAL sampling periods with"
echo "each interval lasting $SECS seconds"
echo -e "\n...Please wait while gathering statistics...\n"
# Use "iostat" to monitor the CPU utilization and
# remove all lines that contain alphabetic characters
# and blank spaces. Then use the previously defined
# field numbers, for example, F1=4,to point directly
# to the 4th position, for this example. The syntax
# for this techniques is ==> $.$F1..
iostat $SWITCH $SECS $INTERVAL | egrep -v '[a-zA-Z]|^$' \
| awk '{print $'$F1', $'$F2', $'$F3', $'$F4'}' \
| while read FIRST SECOND THIRD FOURTH
do
if ((STATCOUNT == 1)) # Loop counter to get the second set
then # of data produced by "iostat"
case $OS in # Show the results based on the UNIX flavor
AIX)
echo -e "\nUser part is ${FIRST}%"
echo "System part is ${SECOND}%"
echo "Idle part is ${THIRD}%"
echo -e "I/O wait state is ${FOURTH}%\n"
;;
HP-UX|OpenBSD)
echo -e "\nUser part is ${FIRST}%"
echo "Nice part is ${SECOND}%"
echo "System part is ${THIRD}%"
echo -e "Idle time is ${FOURTH}%\n"
;;
SunOS|Linux)
echo -e "\nUser part is ${FIRST}%"
echo "System part is ${SECOND}%"
echo "I/O Wait is ${THIRD}%"
echo -e "Idle time is ${FOURTH}%\n"
;;
esac
fi
((STATCOUNT = STATCOUNT + 1)) # Increment the loop counter
done

109
chapter19/iostat_loadmon.ksh Executable file
View File

@@ -0,0 +1,109 @@
#!/bin/ksh
#
# SCRIPT: iostat_loadmon.ksh
# AUTHOR: Randy Michael
# DATE: 07/26/2007
# REV: 1.0.P
# PLATFORM: AIX, HP-UX, Linux, and Solaris
#
# PURPOSE: This shell script take two samples of the CPU
# usage using the "iostat" command. The first set of
# data is an average since the last system reboot. The
# second set of data is an average over the sampling
# period, or $INTERVAL. The result of the data aquired
# during the sampling perion is shown to the user based
# on the UNIX operating system that this shell script is
# executing on. Different UNIX flavors have differing
# outputs and the fields vary too.
#
# REV LIST:
#
#
# set -n # Uncomment to check the script syntax without any execution
# set -x # Uncomment to debug this shell script
#
###################################################
############# DEFINE VARIABLES HERE ###############
###################################################
SECONDS=300 # Defines the number of seconds for each sample
INTERVAL=2 # Defines the total number of sampling intervals
STATCOUNT=0 # Initialize a loop counter to 0, zero
OS=$(uname) # Defines the UNIX flavor
###################################################
##### SETUP THE ENVIRONMENT FOR EACH OS HERE ######
###################################################
# These "F-numbers" point to the correct field in the
# command output for each UNIX flavor.
case $OS in
AIX|HP-UX) SWITCH='-t'
F1=3
F2=4
F3=5
F4=6
echo "\nThe Operating System is $OS\n"
;;
Linux|SunOS) SWITCH='-c'
F1=1
F2=2
F3=3
F4=4
echo "\nThe Operating System is $OS\n"
;;
*) echo "\nERROR: $OS is not a supported operating system\n"
echo "\n\t...EXITING...\n"
exit 1
;;
esac
###################################################
######## BEGIN GATHERING STATISTICS HERE ##########
###################################################
echo "Gathering CPU Statistics using vmstat...\n"
echo "There are $INTERVAL sampling periods with"
echo "each interval lasting $SECONDS seconds"
echo "\n...Please wait while gathering statistics...\n"
# Use "iostat" to monitor the CPU utilization and
# remove all lines that contain alphabetic characters
# and blank spaces. Then use the previously defined
# field numbers, for example F1=4,to point directly
# to the 4th position, for this example. The syntax
# for this techniques is ==> $'$F1'.
iostat $SWITCH $SECONDS $INTERVAL | egrep -v '[a-zA-Z]|^$' \
| awk '{print $'$F1', $'$F2', $'$F3', $'$F4'}' \
| while read FIRST SECOND THIRD FORTH
do
if ((STATCOUNT == 1)) # Loop counter to get the second set
then # of data produces by "iostat"
case $OS in # Show the results based on the UNIX flavor
AIX)
echo "\nUser part is ${FIRST}%"
echo "System part is ${SECOND}%"
echo "Idle part is ${THIRD}%"
echo "I/O wait state is ${FORTH}%\n"
;;
HP-UX|Linux)
echo "\nUser part is ${FIRST}%"
echo "Nice part is ${SECOND}%"
echo "System part is ${THIRD}%"
echo "Idle time is ${FORTH}%\n"
;;
SunOS)
echo "\nUser part is ${FIRST}%"
echo "System part is ${SECOND}%"
echo "I/O Wait is ${THIRD}%"
echo "Idle time is ${FORTH}%\n"
;;
esac
fi
((STATCOUNT = STATCOUNT + 1)) # Increment the loop counter
done

92
chapter19/sar_loadmon.ksh Executable file
View File

@@ -0,0 +1,92 @@
#!/bin/ksh
#
# SCRIPT: sar_loadmon.ksh
# AUTHOR: Randy Michael
# DATE: 07/26/2007
# REV: 1.0.P
# PLATFORM: AIX, HP-UX, Linux, and Solaris
#
# PURPOSE: This shell script take multiple samples of the CPU
# usage using the "sar" command. The average or
# sample periods is shown to the user based on the
# UNIX operating system that this shell script is
# executing on. Different UNIX flavors have differing
# outputs and the fields vary too.
#
# REV LIST:
#
#
# set -n # Uncomment to check the script syntax without any execution
# set -x # Uncomment to debug this shell script
#
###################################################
############# DEFINE VARIABLES HERE ###############
###################################################
SECONDS=30 # Defines the number of seconds for each sample
INTERVAL=10 # Defines the total number of sampling intervals
OS=$(uname) # Defines the UNIX flavor
###################################################
##### SETUP THE ENVIRONMENT FOR EACH OS HERE ######
###################################################
# These "F-numbers" point to the correct field in the
# command output for each UNIX flavor.
case $OS in
AIX|HP-UX|SunOS)
F1=2
F2=3
F3=4
F4=5
echo "\nThe Operating System is $OS\n"
;;
Linux)
F1=3
F2=4
F3=5
F4=6
echo "\nThe Operating System is $OS\n"
;;
*) echo "\nERROR: $OS is not a supported operating system\n"
echo "\n\t...EXITING...\n"
exit 1
;;
esac
###################################################
######## BEGIN GATHERING STATISTICS HERE ##########
###################################################
echo "Gathering CPU Statistics using sar...\n"
echo "There are $INTERVAL sampling periods with"
echo "each interval lasting $SECONDS seconds"
echo "\n...Please wait while gathering statistics...\n"
# This "sar" command take $INTERVAL samples, each lasting
# $SECONDS seconds. The average of this output is captured.
sar $SECONDS $INTERVAL | grep Average \
| awk '{print $'$F1', $'$F2', $'$F3', $'$F4'}' \
| while read FIRST SECOND THIRD FORTH
do
# Based on the UNIX Flavor, tell the user the
# result of the statistics gathered.
case $OS in
AIX|HP-UX|SunOS)
echo "\nUser part is ${FIRST}%"
echo "System part is ${SECOND}%"
echo "I/O wait state is ${FORTH}%"
echo "Idle time is ${FORTH}%\n"
;;
Linux)
echo "\nUser part is ${FIRST}%"
echo "Nice part is ${SECOND}%"
echo "System part is ${THIRD}%"
echo "Idle time is ${FORTH}%\n"
;;
esac
done

41
chapter19/uptime_fieldtest.ksh Executable file
View File

@@ -0,0 +1,41 @@
#!/bin/ksh
#
# SCRIPT: uptime_fieldtest.ksh
# AUTHOR: Randy Michael
# DATE: 07/28/2002
# PLATFORM: Any UNIX
# PURPOSE: This shell script is used to demonstrate how the
# average load statistics field shift depending on
# how long it has been since the last system reboot.
# The options are "min", "day", "hr" and combinations.
# If all other tests fail then the system has been running
# for 1-23 hours.
echo "\n" # Write one blank new line to the screen
# Show a current uptime output
uptime
# Find the correct field bases on how long the system has been up.
if $(uptime | grep day | grep min >/dev/null)
then
FIELD=11
elif $(uptime | grep day | grep hr >/dev/null)
then
FIELD=11
elif $(uptime | grep day >/dev/null)
then
FIELD=10
elif $(uptime | grep min >/dev/null)
then
FIELD=9
else
FIELD=8
fi
# Display the correct field.
echo "\nField is $FIELD \n"

97
chapter19/uptime_loadmon.bash Executable file
View File

@@ -0,0 +1,97 @@
#!/bin/bash
#
# SCRIPT: uptime_loadmon.bash
# AUTHOR: Randy Michael
# DATE: 12/16/2007
# REV: 1.0.P
# PLATFORM: AIX, HP-UX, Linux, OpenBSD, and Solaris
#
# PURPOSE: This shell script uses the "uptime" command to
# extract the most current load average data, which
# in this case is the average number of jobs in the
# run queue.
#
# set -x # Uncomment to debug this shell script
# set -n # Uncomment to check script syntax without any execution
#
###################################################
############# DEFINE VARIABLES HERE ###############
###################################################
MAXLOAD=2.00
# Extract the interger and decimal parts of $MAXLOAD
MAXLOAD_INT=$(echo $MAXLOAD | awk -F '.' '{print $1}')
MAXLOAD_DEC=$(echo $MAXLOAD | awk -F '.' '{print $2}')
# Check the UNIX flavor for the correct uptime values
# AIX specifies load as the last 5, 10, and 15 minutes.
# The other UNIX flavors specifies the load in the last
# 1, 5, and 15 minutes.
case $(uname) in
AIX) L1=5
L2=10
L3=15
;;
*)
L1=1
L2=5
L3=15
;;
esac
###################################################
# DEFINE FUNCTIONS HERE
###################################################
function get_max
{
# This function return the number of auguments
# presented to the function
#
(($# == 0)) && return -1
echo $#
}
###################################################
# BEGINNING OF MAIN
###################################################
echo -e "\nGathering System Load Average using the \"uptime\" command\n"
# This next command statement extracts the latest
# load statistics no matter what the UNIX flavor is.
NUM_ARGS=$(get_max $(uptime)) # Get the total number of fields in uptime output
((NUM_ARGS == -1)) && echo "ERROR: get_max Function Error...EXITING..."\
&& exit 2
# Extract the data for the last 5, 10, and 15 minutes
ARGM2=$(((NUM_ARGS - 2))) # Subtract 2 from the total
ARGM1=$(((NUM_ARGS - 1))) # Subtract 1 from the total
ARGM=$NUM_ARGS # Last value in string
uptime | sed s/,//g | awk '{print $'$ARGM2', $'$ARGM1', $'$ARGM'}' \
| while read LAST5 LAST10 LAST15
do
echo $LAST5 | awk -F '.' '{print $1, $2}' \
| while read INT DEC
do
if (( INT > MAXLOAD_INT ))
then
echo -e "\nWARNING: System load has \
reached ${LAST5}\n"
fi
echo "System load average for the last $L1 minutes is $LAST5"
echo "System load average for the last $L2 minutes is $LAST10"
echo "System load average for the last $L3 minutes is $LAST15"
echo -e "\nThe load threshold is set to ${MAXLOAD}\n"
done
done

76
chapter19/uptime_loadmon.ksh Executable file
View File

@@ -0,0 +1,76 @@
#!/bin/ksh
#
# SCRIPT: uptime_loadmon.ksh
# AUTHOR: Randy Michael
# DATE: 07/26/2007
# REV: 1.0.P
# PLATFORM: AIX, HP-UX, Linux, and Solaris
#
# PURPOSE: This shell script uses the "uptime" command to
# extract the most current load average data. There
# is a special need in this script to determine
# how long the system has been running since the
# last reboot. The load average field "floats"
# during the first 24 hours after a system restart.
#
# set -x # Uncomment to debug this shell script
# set -n # Uncomment to check script syntax without any execution
#
###################################################
############# DEFINE VARIABLES HERE ###############
###################################################
SECONDS=30
INTERVAL=2
MAXLOAD=2.00
typeset -i INT_MAXLOAD=$MAXLOAD
# Find the correct field to extract based on how long
# the system has been up, or since the last reboot.
if $(uptime | grep day | grep min >/dev/null)
then
FIELD=11
elif $(uptime | grep day | grep hrs >/dev/null)
then
FIELD=11
elif $(uptime | grep day >/dev/null)
then
FIELD=10
elif $(uptime | grep min >/dev/null)
then
FIELD=9
else
FIELD=8
fi
###################################################
######## BEGIN GATHERING STATISTICS HERE ##########
###################################################
echo "\nGathering System Load Average using the \"uptime\" command\n"
# This next command statement extracts the latest
# load statistics no matter what the UNIX flavor is.
LOAD=$(uptime | sed s/,//g | awk '{print $'$FIELD'}')
# We need an integer representation of the $LOAD
# variable to do the test for the load going over
# the set threshold defince by the $INT_MAXLOAD
# variable
typeset -i INT_LOAD=$LOAD
# If the current load has exceeded the threshold then
# issue a warning message. The next step always shows
# the user what the current load and threshold values
# are set to.
((INT_LOAD >= INT_MAXLOAD)) && echo "\nWARNING: System load has \
reached ${LOAD}\n"
echo "\nSystem load value is currently at ${LOAD}"
echo "The load threshold is set to ${MAXLOAD}\n"

123
chapter19/vmstat_loadmon.bash Executable file
View File

@@ -0,0 +1,123 @@
#!/bin/bash
#
# SCRIPT: vmstat_loadmon.bash
# AUTHOR: Randy Michael
# DATE: 12/20/2007
# REV: 1.0.P
# PLATFORM: AIX, HP-UX, Linux, OpenBSD, and Solaris
#
# PURPOSE: This shell script takes two samples of the CPU
# usage using the command. The first set of
# data is an average since the last system reboot. The
# second set of data is an average over the sampling
# period, or $INTERVAL. The result of the data acquired
# during the sampling period is shown to the user based
# on the UNIX operating system that this shell script is
# executing on. Different UNIX flavors have differing
# outputs and the fields vary too.
#
# REV LIST:
#
#
# set -n # Uncomment to check the script syntax without any execution
# set -x # Uncomment to debug this shell script
#
###################################################
############# DEFINE VARIABLES HERE ###############
###################################################
SECS=300 # Defines the number of seconds for each sample
INTERVAL=2 # Defines the total number of sampling intervals
STATCOUNT=0 # Initializes a loop counter to 0, zero
OS=$(uname) # Defines the UNIX flavor
###################################################
##### SET UP THE ENVIRONMENT FOR EACH OS HERE ######
###################################################
# These "F-numbers" point to the correct field in the
# command output for each UNIX flavor.
OS=$(uname)
case $OS in
AIX)
F1=14
F2=15
F3=16
F4=17
echo -e "\nThe Operating System is $OS\n"
;;
HP-UX)
F1=16
F2=17
F3=18
F4=1 # This "F4=1" is bogus and not used for HP-UX
echo -e "\nThe Operating System is $OS\n"
;;
Linux)
F1=13
F2=14
F3=15
F4=16
echo -e "\nThe Operating System is $OS\n"
;;
OpenBSD)
F1=17
F2=18
F3=19
F4=1 # This "F4=1" is bogus and not used for Linux
echo -e "\nThe Operating System is $OS\n"
;;
SunOS)
F1=20
F2=21
F3=22
F4=1 # This "F4=1" is bogus and not used for SunOS
echo -e "\nThe Operating System is $OS\n"
;;
*) echo -e "\nERROR: $OS is not a supported operating system\n"
echo -e "\n\t...EXITING...\n"
exit 1
;;
esac
###################################################
######## BEGIN GATHERING STATISTICS HERE ##########
###################################################
echo -e "Gathering CPU Statistics using vmstat...\n"
echo "There are $INTERVAL sampling periods with"
echo "each interval lasting $SECS seconds"
echo -e "\n...Please wait while gathering statistics...\n"
# Use "vmstat" to montor the CPU utilization and
# remove all lines that contain alphabetic characters
# and blank spaces. Then use the previously defined
# field numbers, for example F1=20,to point directly
# to the 20th position, for this example. The syntax
# for this technique is ==> $.$F1. and points directly
# to the $20 positional parameter.
vmstat $SECS $INTERVAL | egrep -v '[a-zA-Z]|^$' \
| awk '{print $'$F1', $'$F2', $'$F3', $'$F4'}' \
| while read FIRST SECOND THIRD FOURTH
do
if ((STATCOUNT == 1)) # Loop counter to get the second set
then # of data produced by
case $OS in # Show the results based on the UNIX flavor
AIX|Linux)
echo -e "\nUser part is ${FIRST}%"
echo "System part is ${SECOND}%"
echo "Idle part is ${THIRD}%"
echo -e "I/O wait state is ${FOURTH}%\n"
;;
HP-UX|OpenBSD|SunOS)
echo -e "\nUser part is ${FIRST}%"
echo "System part is ${SECOND}%"
echo -e "Idle time is ${THIRD}%\n"
;;
esac
fi
((STATCOUNT = STATCOUNT + 1)) # Increment the loop counter
done

120
chapter19/vmstat_loadmon.ksh Executable file
View File

@@ -0,0 +1,120 @@
#!/bin/ksh
#
# SCRIPT: vmstat_loadmon.ksh
# AUTHOR: Randy Michael
# DATE: 07/26/2002
# REV: 1.0.P
# PLATFORM: AIX, HP-UX, Linux, and Solaris
#
# PURPOSE: This shell script take two samples of the CPU
# usage using the "vmstat" command. The first set of
# data is an average since the last system reboot. The
# second set of data is an average over the sampling
# period, or $INTERVAL. The result of the data aquired
# during the sampling perion is shown to the user based
# on the UNIX operating system that this shell script is
# executing on. Different UNIX flavors have differing
# outputs and the fields vary too.
#
# REV LIST:
#
#
# set -n # Uncomment to check the script syntax without any execution
# set -x # Uncomment to debug this shell script
#
###################################################
############# DEFINE VARIABLES HERE ###############
###################################################
SECONDS=300 # Defines the number of seconds for each sample
INTERVAL=2 # Defines the total number of sampling intervals
STATCOUNT=0 # Initialize a loop counter to 0, zero
OS=$(uname) # Defines the UNIX flavor
###################################################
##### SETUP THE ENVIRONMENT FOR EACH OS HERE ######
###################################################
# These "F-numbers" point to the correct field in the
# command output for each UNIX flavor.
case $OS in
AIX) # AIX has four relative columns in the output
F1=14
F2=15
F3=16
F4=17
echo "\nThe Operating System is $OS\n"
;;
HP-UX) # HP-UX only has three relative columns in the output
F1=16
F2=17
F3=18
F4=1 # This "F4=1" is bogus and not used for HP-UX
echo "\nThe Operating System is $OS\n"
;;
Linux) # Linux only has three relative columns in the output
F1=14
F2=15
F3=16
F4=1 # This "F4=1" is bogus and not used for Linux
echo "\nThe Operating System is $OS\n"
;;
SunOS) # SunOS only has three relative columns in the output
F1=20
F2=21
F3=22
F4=1 # This "F4=1" is bogus and not used for SunOS
echo "\nThe Operating System is $OS\n"
;;
*) echo "\nERROR: $OS is not a supported operating system\n"
echo "\n\t...EXITING...\n"
exit 1
;;
esac
###################################################
######## BEGIN GATHERING STATISTICS HERE ##########
###################################################
echo "Gathering CPU Statistics using vmstat...\n"
echo "There are $INTERVAL sampling periods with"
echo "each interval lasting $SECONDS seconds"
echo "\n...Please wait while gathering statistics...\n"
# Use "vmstat" to monitor the CPU utilization and
# remove all lines that contain alphabetic characters
# and blank spaces. Then use the previously defined
# field numbers, for example F1=20,to point directly
# to the 20th position, for this example. The syntax
# for this techniques is ==> $'$F1', and points directly
# to the $20 positional parameter.
vmstat $SECONDS $INTERVAL | egrep -v '[a-zA-Z]|^$' \
| awk '{print $'$F1', $'$F2', $'$F3', $'$F4'}' \
| while read FIRST SECOND THIRD FORTH
do
if ((STATCOUNT == 1)) # Loop counter to get the second set
then # of data produces by "vmstat"
case $OS in # Show the results based on the UNIX flavor
AIX)
echo "\nUser part is ${FIRST}%"
echo "System part is ${SECOND}%"
echo "Idle part is ${THIRD}%"
echo "I/O wait state is ${FORTH}%\n"
;;
HP-UX|Linux|SunOS)
echo "\nUser part is ${FIRST}%"
echo "System part is ${SECOND}%"
echo "Idle time is ${THIRD}%\n"
;;
esac
fi
((STATCOUNT = STATCOUNT + 1)) # Increment the loop counter
done