mirror of https://github.com/tLDP/LDP
new files
This commit is contained in:
parent
03ddc10f2d
commit
2cc6f39586
|
@ -0,0 +1,54 @@
|
|||
#!/bin/bash
|
||||
# broken-link.sh
|
||||
# Written by Lee bigelow <ligelowbee@yahoo.com>
|
||||
# Used with permission.
|
||||
|
||||
#A pure shell script to find dead symlinks and output them quoted
|
||||
#so they can be fed to xargs and dealt with :)
|
||||
#eg. broken-link.sh /somedir /someotherdir|xargs rm
|
||||
#
|
||||
#This, however, is a better method:
|
||||
#
|
||||
#find "somedir" -type l -print0|\
|
||||
#xargs -r0 file|\
|
||||
#grep "broken symbolic"|
|
||||
#sed -e 's/^\|: *broken symbolic.*$/"/g'
|
||||
#
|
||||
#but that wouldn't be pure bash, now would it.
|
||||
#Caution: beware the /proc file system and any circular links!
|
||||
##############################################################
|
||||
|
||||
|
||||
#If no args are passed to the script set directorys to search
|
||||
#to current directory. Otherwise set the directorys to search
|
||||
#to the agrs passed.
|
||||
####################
|
||||
[ $# -eq 0 ] && directorys=`pwd` || directorys=$@
|
||||
|
||||
#Setup the function linkchk to check the directory it is passed
|
||||
#for files that are links and don't exist, then print them quoted.
|
||||
#If one of the elements in the directory is a subdirectory then
|
||||
#send that send that subdirectory to the linkcheck function.
|
||||
##########
|
||||
linkchk () {
|
||||
for element in $1/*; do
|
||||
[ -h "$element" -a ! -e "$element" ] && echo \"$element\"
|
||||
[ -d "$element" ] && linkchk $element
|
||||
# Of course, '-h' tests for symbolic link, '-d' for directory.
|
||||
done
|
||||
}
|
||||
|
||||
#Send each arg that was passed to the script to the linkchk function
|
||||
#if it is a valid directoy. If not, then print the error message
|
||||
#and usage info.
|
||||
################
|
||||
for directory in $directorys; do
|
||||
if [ -d $directory ]
|
||||
then linkchk $directory
|
||||
else
|
||||
echo "$directory is not a directory"
|
||||
echo "Usage: $0 dir1 dir2 ..."
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,53 @@
|
|||
# Albert Reiner gives an example of how to use "continue N":
|
||||
# ---------------------------------------------------------
|
||||
|
||||
# Suppose I have a large number of jobs that need to be run, with
|
||||
#+ any data that is to be treated in files of a given name pattern in a
|
||||
#+ directory. There are several machines that access this directory, and
|
||||
#+ I want to distribute the work over these different boxen. Then I
|
||||
#+ usually nohup something like the following on every box:
|
||||
|
||||
while true
|
||||
do
|
||||
for n in .iso.*
|
||||
do
|
||||
[ "$n" = ".iso.opts" ] && continue
|
||||
beta=${n#.iso.}
|
||||
[ -r .Iso.$beta ] && continue
|
||||
[ -r .lock.$beta ] && sleep 10 && continue
|
||||
lockfile -r0 .lock.$beta || continue
|
||||
echo -n "$beta: " `date`
|
||||
run-isotherm $beta
|
||||
date
|
||||
ls -alF .Iso.$beta
|
||||
[ -r .Iso.$beta ] && rm -f .lock.$beta
|
||||
continue 2
|
||||
done
|
||||
break
|
||||
done
|
||||
|
||||
# The details, in particular the sleep N, are particular to my
|
||||
#+ application, but the general pattern is:
|
||||
|
||||
while true
|
||||
do
|
||||
for job in {pattern}
|
||||
do
|
||||
{job already done or running} && continue
|
||||
{mark job as running, do job, mark job as done}
|
||||
continue 2
|
||||
done
|
||||
break # Or something like `sleep 600' to avoid termination.
|
||||
done
|
||||
|
||||
# This way the script will stop only when there are no more jobs to do
|
||||
#+ (including jobs that were added during runtime). Through the use
|
||||
#+ of appropriate lockfiles it can be run on several machines
|
||||
#+ concurrently without duplication of calculations [which run a couple
|
||||
#+ of hours in my case, so I really want to avoid this]. Also, as search
|
||||
#+ always starts again from the beginning, one can encode priorities in
|
||||
#+ the file names. Of course, one could also do this without `continue 2',
|
||||
#+ but then one would have to actually check whether or not some job
|
||||
#+ was done (so that we should immediately look for the next job) or not
|
||||
#+ (in which case we terminate or sleep for a long time before checking
|
||||
#+ for a new job).
|
|
@ -0,0 +1,19 @@
|
|||
In the Perl script "test.pl":
|
||||
...
|
||||
my $WEBROOT = <WEBROOT_PATH>;
|
||||
...
|
||||
|
||||
To force variable substitution try:
|
||||
$export WEBROOT_PATH=/usr/local/webroot
|
||||
$sed 's/<WEBROOT_PATH>/$WEBROOT_PATH/' < test.pl > out
|
||||
|
||||
But this just gives:
|
||||
my $WEBROOT = $WEBROOT_PATH;
|
||||
|
||||
However:
|
||||
$export WEBROOT_PATH=/usr/local/webroot
|
||||
$eval sed 's/<WEBROOT_PATH>/$WEBROOT_PATH/' < test.pl > out
|
||||
# ====
|
||||
|
||||
That works fine, and gives the expected substitution:
|
||||
my $WEBROOT = /usr/local/webroot
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
# paragraph-space.sh
|
||||
|
||||
# Inserts a blank line between paragraphs of a single-spaced text file.
|
||||
# Usage: $0 <FILENAME
|
||||
|
||||
MINLEN=45 # May need to change this value.
|
||||
# Assume lines shorter than $MINLEN characters
|
||||
#+ terminate a paragraph.
|
||||
|
||||
while read line # For as many lines as the input file has...
|
||||
do
|
||||
echo "$line" # Output the line itself.
|
||||
|
||||
len=${#line}
|
||||
if [ "$len" -lt "$MINLEN" ]
|
||||
then echo # Add a blank line after short line.
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,43 @@
|
|||
#!/bin/bash
|
||||
# pick-card.sh
|
||||
|
||||
# This is an example of choosing a random element of an array.
|
||||
|
||||
|
||||
# Pick a card, any card.
|
||||
|
||||
Suites="Clubs
|
||||
Diamonds
|
||||
Hearts
|
||||
Spades"
|
||||
|
||||
Denominations="2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
Jack
|
||||
Queen
|
||||
King
|
||||
Ace"
|
||||
|
||||
suite=($Suites) # Read into array variable.
|
||||
denomination=($Denominations)
|
||||
|
||||
num_suites=${#suite[*]} # Count how many elements.
|
||||
num_denominations=${#denomination[*]}
|
||||
|
||||
echo -n "${denomination[$((RANDOM%num_denominations))]} of "
|
||||
echo ${suite[$((RANDOM%num_suites))]}
|
||||
|
||||
|
||||
# $bozo sh pick-cards.sh
|
||||
# Jack of Clubs
|
||||
|
||||
|
||||
# Thank you, "jipe," for pointing out this use of $RANDOM.
|
||||
exit 0
|
Loading…
Reference in New Issue