Fix bash scripts
This commit is contained in:
64
chapter1/coprocess.sh
Executable file
64
chapter1/coprocess.sh
Executable file
@@ -0,0 +1,64 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# SCRIPT: coprocess.sh
|
||||||
|
# AUTHOR: Fabio Scotto di Santolo
|
||||||
|
# DATE: 29/07/2020
|
||||||
|
# REV: 1.1.A
|
||||||
|
#
|
||||||
|
# PLATFORM: Not platform dependent
|
||||||
|
#
|
||||||
|
# PURPOSE:
|
||||||
|
#
|
||||||
|
# REV LIST:
|
||||||
|
#
|
||||||
|
##########################################################
|
||||||
|
# DEFINE FUNCTIONS HERE
|
||||||
|
##########################################################
|
||||||
|
|
||||||
|
function trap_exit
|
||||||
|
{
|
||||||
|
# Tell the co-process to break out of the loop
|
||||||
|
break_out='Y'
|
||||||
|
print -p $break_out # Use "print -p" to talk to the co-process
|
||||||
|
}
|
||||||
|
|
||||||
|
function proc_watch
|
||||||
|
{
|
||||||
|
# This function is started as a co-process
|
||||||
|
while : # Loop forever
|
||||||
|
do
|
||||||
|
read $break_out # Do NOT need "-p" to read!
|
||||||
|
if [[ $break_out == 'Y' ]];
|
||||||
|
then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
##########################################################
|
||||||
|
# BEGINNING OF MAIN
|
||||||
|
##########################################################
|
||||||
|
|
||||||
|
trap 'trap_exit; exit 2' 1 2 3 15
|
||||||
|
|
||||||
|
total_seconds=300
|
||||||
|
break_out='N'
|
||||||
|
|
||||||
|
coproc proc_watch # Start proc_watch as a co-process!!!
|
||||||
|
pw_pid=$1 # Process ID of the last background job
|
||||||
|
|
||||||
|
until [ total_seconds -eq 0 ];
|
||||||
|
do
|
||||||
|
(( total_seconds=total_seconds - 1 ))
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
break_out='Y'
|
||||||
|
|
||||||
|
# Use "print -p" to communicate with the co-process variable
|
||||||
|
print -p $break_out
|
||||||
|
|
||||||
|
kill $pw_pid # Kill the background co-process
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
# End of script
|
||||||
38
chapter1/shifting.sh
Executable file
38
chapter1/shifting.sh
Executable file
@@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# SCRIPT: shifting.sh
|
||||||
|
# AUTHOR: Fabio Scotto di Santolo
|
||||||
|
# DATE: 28/07/2020
|
||||||
|
# REV: 1.1.A
|
||||||
|
#
|
||||||
|
# PLATFORM: Not platform dependent
|
||||||
|
#
|
||||||
|
# PURPOSE: This script is used to process all of the tokens which
|
||||||
|
# are pointed to by the command-line arguments $1, $2, $3, etc...
|
||||||
|
#
|
||||||
|
# REV LIST:
|
||||||
|
#
|
||||||
|
##########################################################
|
||||||
|
# DEFINE FILES AND VARIABLES HERE
|
||||||
|
##########################################################
|
||||||
|
|
||||||
|
total=0 # initialize the total counter to zero
|
||||||
|
|
||||||
|
##########################################################
|
||||||
|
# BEGINNING OF MAIN
|
||||||
|
##########################################################
|
||||||
|
|
||||||
|
# Start a while loop
|
||||||
|
|
||||||
|
for token in $*
|
||||||
|
do
|
||||||
|
total=`expr $total + 1` # A little math in the
|
||||||
|
# shell script, a running
|
||||||
|
# total of tokens processed.
|
||||||
|
|
||||||
|
shift # Grab the next token, i.e. $2 become $1
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Total number of token processed: $total"
|
||||||
|
# End of script
|
||||||
@@ -32,7 +32,7 @@ typeset -i MB_SIZE=$1
|
|||||||
typeset -i RN
|
typeset -i RN
|
||||||
typeset -i i=1
|
typeset -i i=1
|
||||||
typeset -i X=0
|
typeset -i X=0
|
||||||
WORKDIR=/scripts
|
WORKDIR=./scripts
|
||||||
OUTFILE=${WORKDIR}/largefile.random.txt
|
OUTFILE=${WORKDIR}/largefile.random.txt
|
||||||
>$OUTFILE
|
>$OUTFILE
|
||||||
THIS_SCRIPT=$(basename $0)
|
THIS_SCRIPT=$(basename $0)
|
||||||
@@ -42,7 +42,7 @@ CHAR_FILE=${WORKDIR}/char_file.txt
|
|||||||
# DEFINE FUNCTIONS HERE
|
# DEFINE FUNCTIONS HERE
|
||||||
##########################################
|
##########################################
|
||||||
|
|
||||||
build_random_line ()
|
function build_random_line
|
||||||
{
|
{
|
||||||
# This function extracts random characters
|
# This function extracts random characters
|
||||||
# from the KEYS array by using the RANDOM
|
# from the KEYS array by using the RANDOM
|
||||||
@@ -50,7 +50,7 @@ build_random_line ()
|
|||||||
|
|
||||||
C=1
|
C=1
|
||||||
LINE=
|
LINE=
|
||||||
until (( C > 79 ))
|
until [[ C > 79 ]]
|
||||||
do
|
do
|
||||||
LINE="${LINE}${KEYS[$(($RANDOM % X + 1))]}"
|
LINE="${LINE}${KEYS[$(($RANDOM % X + 1))]}"
|
||||||
(( C = C + 1 ))
|
(( C = C + 1 ))
|
||||||
|
|||||||
72
chapter2/scripts/char_file.txt
Normal file
72
chapter2/scripts/char_file.txt
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
||||||
|
8
|
||||||
|
9
|
||||||
|
0
|
||||||
|
q
|
||||||
|
w
|
||||||
|
e
|
||||||
|
r
|
||||||
|
t
|
||||||
|
y
|
||||||
|
u
|
||||||
|
i
|
||||||
|
o
|
||||||
|
p
|
||||||
|
a
|
||||||
|
s
|
||||||
|
d
|
||||||
|
f
|
||||||
|
g
|
||||||
|
h
|
||||||
|
j
|
||||||
|
k
|
||||||
|
l
|
||||||
|
z
|
||||||
|
x
|
||||||
|
c
|
||||||
|
v
|
||||||
|
b
|
||||||
|
n
|
||||||
|
m
|
||||||
|
Q
|
||||||
|
W
|
||||||
|
E
|
||||||
|
R
|
||||||
|
T
|
||||||
|
Y
|
||||||
|
U
|
||||||
|
I
|
||||||
|
O
|
||||||
|
P
|
||||||
|
A
|
||||||
|
S
|
||||||
|
D
|
||||||
|
F
|
||||||
|
G
|
||||||
|
H
|
||||||
|
J
|
||||||
|
K
|
||||||
|
L
|
||||||
|
Z
|
||||||
|
X
|
||||||
|
C
|
||||||
|
V
|
||||||
|
B
|
||||||
|
N
|
||||||
|
M
|
||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
||||||
|
8
|
||||||
|
9
|
||||||
12800
chapter2/scripts/largefile.random.txt
Normal file
12800
chapter2/scripts/largefile.random.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user