mirror of https://github.com/tLDP/LDP
*** empty log message ***
This commit is contained in:
parent
8a9055d909
commit
39f12d6ccc
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# exercising-dd.sh
|
||||||
|
|
||||||
|
# Script by Stephane Chazelas.
|
||||||
|
# Somewhat modified by document author.
|
||||||
|
|
||||||
|
input_file=$0 # This script.
|
||||||
|
output_file=log.txt
|
||||||
|
n=3
|
||||||
|
p=5
|
||||||
|
|
||||||
|
dd if=$input_file of=$output_file bs=1 skip=$((n-1)) count=$((p-n+1)) 2> /dev/null
|
||||||
|
# Extracts characters n to p from this script.
|
||||||
|
|
||||||
|
# -------------------------------------------------------
|
||||||
|
|
||||||
|
echo -n "hello world" | dd cbs=1 conv=unblock 2> /dev/null
|
||||||
|
# Echoes "hello world" vertically.
|
||||||
|
|
||||||
|
exit 0
|
|
@ -0,0 +1,71 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# multiple-processes.sh: Run multiple processes on an SMP box.
|
||||||
|
|
||||||
|
# Script written by Vernia Damiano.
|
||||||
|
# Used with permission.
|
||||||
|
|
||||||
|
# Must call script with at least one integer parameter
|
||||||
|
#+ (number of concurrent processes).
|
||||||
|
# All other parameters are passed through to the processes started.
|
||||||
|
|
||||||
|
|
||||||
|
INDICE=8 # Total number of process to start
|
||||||
|
TEMPO=5 # Maximum sleep time per process
|
||||||
|
E_BADARGS=65 # No arg(s) passed to script.
|
||||||
|
|
||||||
|
if [ $# -eq 0 ] # Check for at least one argument passed to script.
|
||||||
|
then
|
||||||
|
echo "Usage: `basename $0` number_of_processes [passed params]"
|
||||||
|
exit $E_BADARGS
|
||||||
|
fi
|
||||||
|
|
||||||
|
NUMPROC=$1 # Number of concurrent process
|
||||||
|
shift
|
||||||
|
PARAMETRI=( "$@" ) # Parameters of each process
|
||||||
|
|
||||||
|
function avvia() {
|
||||||
|
local temp
|
||||||
|
local index
|
||||||
|
temp=$RANDOM
|
||||||
|
index=$1
|
||||||
|
shift
|
||||||
|
let "temp %= $TEMPO"
|
||||||
|
let "temp += 1"
|
||||||
|
echo "Starting $index Time:$temp" "$@"
|
||||||
|
sleep ${temp}
|
||||||
|
echo "Ending $index"
|
||||||
|
kill -s SIGRTMIN $$
|
||||||
|
}
|
||||||
|
|
||||||
|
function parti() {
|
||||||
|
if [ $INDICE -gt 0 ] ; then
|
||||||
|
avvia $INDICE "${PARAMETRI[@]}" &
|
||||||
|
let "INDICE--"
|
||||||
|
else
|
||||||
|
trap : SIGRTMIN
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
trap parti SIGRTMIN
|
||||||
|
|
||||||
|
while [ "$NUMPROC" -gt 0 ]; do
|
||||||
|
parti;
|
||||||
|
let "NUMPROC--"
|
||||||
|
done
|
||||||
|
|
||||||
|
wait
|
||||||
|
trap - SIGRTMIN
|
||||||
|
|
||||||
|
exit $?
|
||||||
|
|
||||||
|
: << SCRIPT_AUTHOR_COMMENTS
|
||||||
|
I had the need to run a program, with specified options, on a number of
|
||||||
|
different files, using a SMP machine. So I thought [I'd] keep running
|
||||||
|
a specified number of processes and start a new one each time . . . one
|
||||||
|
of these terminates.
|
||||||
|
|
||||||
|
The "wait" instruction does not help, since it waits for a given process
|
||||||
|
or *all* process started in background. So I wrote [this] bash script
|
||||||
|
that can do the job, using the "trap" instruction.
|
||||||
|
--Vernia Damiano
|
||||||
|
SCRIPT_AUTHOR_COMMENTS
|
|
@ -0,0 +1,32 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# quote-fetch.sh: Download a stock quote.
|
||||||
|
|
||||||
|
|
||||||
|
E_NOPARAMS=66
|
||||||
|
|
||||||
|
if [ -z "$1" ] # Must specify a stock (symbol) to fetch.
|
||||||
|
then echo "Usage: `basename $0` stock-symbol"
|
||||||
|
exit $E_NOPARAMS
|
||||||
|
fi
|
||||||
|
|
||||||
|
stock_symbol=$1
|
||||||
|
|
||||||
|
file_suffix=.html
|
||||||
|
# Fetches an HTML file, so name it appropriately.
|
||||||
|
URL='http://finance.yahoo.com/q?s='
|
||||||
|
# Yahoo finance board, with stock query suffix.
|
||||||
|
|
||||||
|
# -----------------------------------------------------------
|
||||||
|
wget -O ${stock_symbol}${file_suffix} "${URL}${stock_symbol}"
|
||||||
|
# -----------------------------------------------------------
|
||||||
|
|
||||||
|
exit $?
|
||||||
|
|
||||||
|
# Exercises:
|
||||||
|
# ---------
|
||||||
|
#
|
||||||
|
# 1) Add a test to ensure the user running the script is on-line.
|
||||||
|
# (Hint: parse the output of 'ps -ax' for "ppp" or "connect."
|
||||||
|
#
|
||||||
|
# 2) Modify this script to fetch the local weather report,
|
||||||
|
#+ taking the user's zip code as an argument.
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# self-copy.sh
|
||||||
|
|
||||||
|
# This script copies itself.
|
||||||
|
|
||||||
|
file_subscript=copy
|
||||||
|
|
||||||
|
dd if=$0 of=$0.$file_subscript 2>/dev/null
|
||||||
|
# Suppress messages from dd: ^^^^^^^^^^^
|
||||||
|
|
||||||
|
exit $?
|
Loading…
Reference in New Issue