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

11
chapter1/function_elapsed_time Executable file
View File

@@ -0,0 +1,11 @@
elapsed_time ()
{
SEC=$1
(( SEC < 60 )) && echo "[Elapsed time: $SEC seconds]\c"
(( SEC >= 60 && SEC < 3600 )) && echo "[Elapsed time: $(( SEC / 60 )) \
min $(( SEC % 60 )) sec]\c"
(( SEC > 3600 )) && echo "[Elapsed time: $(( SEC / 3600 )) hr \
$(( (SEC % 3600) / 60 )) min $(( (SEC % 3600) % 60 )) sec]\c"
}

26
chapter1/function_ping_host Executable file
View File

@@ -0,0 +1,26 @@
function ping_host
{
HOST=$1 # Grab the host to ping from ARG1.
PING_COUNT=3
PACKET_SIZE=54
# This next case statement executes the correct ping
# command based on the Unix flavor
case $(uname) in
AIX|OpenBSD|Linux)
ping -c${PING_COUNT} $HOST 2>/dev/null
;;
HP-UX)
ping $HOST $PACKET_SIZE $PING_COUNT 2>/dev/null
;;
SunOS)
ping -s $HOST $PACKET_SIZE $PING_COUNT 2>/dev/null
;;
*)
echo "\nERROR: Unsupported Operating System - $(uname)"
echo "\n\t. . .EXITING. . .\n"
exit 1
esac
}

26
chapter1/function_rotate_line Executable file
View File

@@ -0,0 +1,26 @@
function rotate_line
{
INTERVAL=1 # Sleep time between "twirls"
TCOUNT="0" # For each TCOUNT the line twirls one increment
while : # Loop forever. . .until this function is killed
do
TCOUNT=`expr $TCOUNT + 1` # Increment the TCOUNT
case $TCOUNT in
"1") echo .-."\b\c"
sleep $INTERVAL
;;
"2") echo .\\."\b\c"
sleep $INTERVAL
;;
"3") echo "|\b\c"
sleep $INTERVAL
;;
"4") echo "/\b\c"
sleep $INTERVAL
;;
*) TCOUNT="0" ;; # Reset the TCOUNT to "0", zero.
esac
done
}

33
chapter1/generic_rsync.bash Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
#
# SCRIPT: generic_rsync.bash
# AUTHOR: Randy Michael
# DATE: 11/18/2007
# REV: 1.0
# PURPOSE: This is a generic shell script to copy files
# using rsync.
#
# set -n # Uncomment to check script syntax without execution
# set -x # Uncomment to debug this script
#
# REV LIST:
#
#
##############################################
# DEFINE FILES AND VARIABLES HERE
##############################################
# Define the source and destination files/directories
SOURCE_FL="/scripts/"
DESTIN_FL="booboo:/scripts"
##############################################
# BEGINNING OF MAIN
##############################################
# Start the rsync copy
rsync -avz "$SOURCE_FL" "$DESTIN_FL"
# End of generic_rsync.bash

11
chapter1/keyit.dsa Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
#
# SCRIPT: keyit.dsa
#
# PURPOSE: This script is used to set up DSA SSH keys. This script must
# be executed by the user who needs the keys setup.
REM_HOST=$1
cat $HOME/.ssh/id_dsa.pub | ssh $REM_HOST "cat >> ~/.ssh/authorized_keys"

11
chapter1/keyit.rsa Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
#
# SCRIPT: keyit.rsa
#
# PURPOSE: This script is used to set up RSA SSH keys.
# This script must be executed by the user who needs the keys setup.
REM_HOST=$1
cat $HOME/.ssh/id_rsa.pub | ssh $REM_HOST "cat >> ~/.ssh/authorized_keys"

50
chapter1/script.stub Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/bash
#
# SCRIPT: NAME_of_SCRIPT
# AUTHOR: AUTHORS_NAME
# DATE: DATE_of_CREATION
# REV: 1.1.A (Valid are A, B, D, T, Q, and P)
# (For Alpha, Beta, Dev, Test, QA, and Production)
#
# PLATFORM: (SPECIFY: AIX, HP-UX, Linux, OpenBSD, Solaris, other flavor,
# or Not platform dependent)
#
# REQUIREMENTS: If this script has requirements that need to be noted, this
# is the place to spell those requirements in detail.
#
# EXAMPLE: OpenSSH is required for this shell script to work.
#
# PURPOSE: Give a clear, and if necessary, long, description of the
# purpose of the shell script. This will also help you stay
# focused on the task at hand.
#
# REV LIST:
# DATE: DATE_of_REVISION
# BY: AUTHOR_of_MODIFICATION
# MODIFICATION: Describe what was modified, new features, etc--
#
#
# set -n # Uncomment to check script syntax, without execution.
# # NOTE: Do not forget to put the # comment back in or
# # the shell script will never execute!
# set -x # Uncomment to debug this shell script
#
##########################################################
# DEFINE FILES AND VARIABLES HERE
##########################################################
THIS_SCRIPT=$(basename $0)
##########################################################
# DEFINE FUNCTIONS HERE
##########################################################
##########################################################
# BEGINNING OF MAIN
##########################################################
# End of script

View File

@@ -0,0 +1,72 @@
#!/bin/bash
#
# SCRIPT: select_system_info_menu.bash
# AUTHOR: Randy Michael
# DATE: 1/17/2008
# REV: 1.0
#
# PURPOSE: This shell script uses the shell's select
# command to create a menu to show system information
# Clear the screen
clear
# Display the menu title header
echo -e "\n\tSYSTEM INFORMATION MENU\n"
# Define the menu prompt
PS3="Select an option and press Enter: "
# The select command defines what the menu
# will look like
select i in OS Host Filesystems Date Users Quit
do
case $i in
OS) echo
uname
;;
Host) echo
hostname
;;
Filesystems)
echo
df -k | more
;;
Date) echo
date
;;
Users) echo
who
;;
Quit) break
;;
esac
# Setting the select command's REPLY variable
# to NULL causes the menu to be redisplayed
REPLY=
# Pause before redisplaying the menu
echo -e "\nPress Enter to Continue...\c"
read
# Ready to redisplay the menu again
# clear the screen
clear
# Display the menu title header
echo -e "\n\tSYSTEM INFORMATION MENU\n"
done
# Clear the screen before exiting
clear

180
chapter1/test_string.ksh Executable file
View File

@@ -0,0 +1,180 @@
#!/bin/ksh
#
# SCRIPT: test_string.ksh
# AUTHOR: Randy Michael
# REV: 1.0.D - Used for developement
# DATE: 10/15/2007
# PLATFORM: Not Platform Dependent
#
# PURPOSE: This script is used to test a character
# string, or variable, for its composition.
# Examples include numeric, lowercase or uppercase
# characters, alpha-numeric characters, and IP address.
#
# REV LIST:
#
#
# set -x # Uncomment to debug this script
# set -n # Uncomment to verify syntax without any execution.
# # REMEMBER: Put the comment back or the script will
# # NOT EXECUTE!
#
####################################################
############## DEFINE FUNCTIONS HERE ###############
####################################################
test_string ()
{
# This function tests a character string
# Must have one argument ($1)
if (( $# != 1 ))
then
# This error would be a programming error
print "ERROR: $(basename $0) requires one argument"
return 1
fi
# Assign arg1 to the variable --> STRING
STRING=$1
# This is where the string test begins
case $STRING in
+([0-9]).+([0-9]).+([0-9]).+([0-9]))
# Testing for an IP address - valid and invalid
INVALID=FALSE
# Separate the integer portions of the "IP" address
# and test to ensure that nothing is greater than 255
# or it is an invalid IP address.
for i in $(echo $STRING | awk -F . '{print $1, $2, $3, $4}')
do
if (( i > 255 ))
then
INVALID=TRUE
fi
done
case $INVALID in
TRUE) print 'INVALID_IP_ADDRESS'
;;
FALSE) print 'VALID_IP_ADDRESS'
;;
esac
;;
+([0-1])) # Testing for 0-1 only
print 'BINARY_OR_POSITIVE_INTEGER'
;;
+([0-7])) # Testing for 0-7 only
print 'OCTAL_OR_POSITIVE_INTEGER'
;;
+([0-9])) # Check for an integer
print 'INTEGER'
;;
+([-0-9])) # Check for a negative whole number
print 'NEGATIVE_WHOLE_NUMBER'
;;
+([0-9]|[.][0-9]))
# Check for a positive floating point number
print 'POSITIVE_FLOATING_POINT'
;;
+(+[0-9][.][0-9]))
# Check for a positive floating point number
# with a + prefix
print 'POSITIVE_FLOATING_POINT'
;;
+(-[0-9][.][0-9]))
# Check for a negative floating point number
print 'NEGATIVE_FLOATING_POINT'
;;
+([-.0-9]))
# Check for a negative floating point number
print 'NEGATIVE_FLOATING_POINT'
;;
+([+.0-9]))
# Check for a positive floating point number
print 'POSITIVE_FLOATING_POINT'
;;
+([a-f])) # Test for hexidecimal or all lowercase characters
print 'HEXIDECIMAL_OR_ALL_LOWERCASE'
;;
+([a-f]|[0-9])) # Test for hexidecimal or all lowercase characters
print 'HEXIDECIMAL_OR_ALL_LOWERCASE_ALPHANUMERIC'
;;
+([A-F])) # Test for hexidecimal or all uppercase characters
print 'HEXIDECIMAL_OR_ALL_UPPERCASE'
;;
+([A-F]|[0-9])) # Test for hexidecimal or all uppercase characters
print 'HEXIDECIMAL_OR_ALL_UPPERCASE_ALPHANUMERIC'
;;
+([a-f]|[A-F]))
# Testing for hexidecimal or mixed-case characters
print 'HEXIDECIMAL_OR_MIXED_CASE'
;;
+([a-f]|[A-F]|[0-9]))
# Testing for hexidecimal/alpha-numeric strings only
print 'HEXIDECIMAL_OR_MIXED_CASE_ALPHANUMERIC'
;;
+([a-z])) # Testing for all lowercase characters only
print 'ALL_LOWERCASE'
;;
+([A-Z])) # Testing for all uppercase numbers only
print 'ALL_UPPERCASE'
;;
+([a-z]|[A-Z]))
# Testing for mixed case alpha strings only
print 'MIXED_CASE'
;;
+([a-z]|[A-Z]|[0-9]))
# Testing for any alpha-numeric string only
print 'ALPHA-NUMERIC'
;;
*) # None of the tests matched the string coposition
print 'INVALID_STRING_COMPOSITION'
;;
esac
}
####################################################
usage ()
{
echo "\nERROR: Please supply one character string or variable\n"
echo "USAGE: $THIS_SCRIPT {character string or variable}\n"
}
####################################################
############# BEGINNING OF MAIN ####################
####################################################
# Query the system for the name of this shell script.
# This is used for the "usage" function.
THIS_SCRIPT=$(basename $0)
# Check for exactly one command-line argument
if (( $# != 1 ))
then
usage
exit 1
fi
# Everything looks okay if we got here. Assign the
# single command-line argument to the variable "STRING"
STRING=$1
# Call the "test_string" function to test the composition
# of the character string stored in the $STRING variable.
test_string $STRING
# End of script