Recursor
Uit Linuxdocs.nl
| Door: | Laurens |
| Versie: | 6 |
| Data: | 15 juli 2011 |
Voorwoord
In het verleden werd uitgegaan van het uitvoeren van commando's als root, tenzij anders aangegeven. Sudoers dienden voor elk commando 'sudo ' te plaatsen.
Bij de reeds bewerkte artikelen wordt nu standaard sudo als beheer opdracht gebruikt.
Recursor
Dit script laat bash commando's uitvoeren vanuit elke directory die wordt aangeduid. Die directory wordt recursief benaderd waar het uit te voeren bash commando steeds wordt herhaald.
Het gebruik is erg eenvoudig:
recursor [directory] [commando] [optie1] [optie2] [optie3]
#!/bin/bash
# Recursor: execute a bash command recursively
# Original script was a rename script. url:
# http://www.linuxquestions.org/questions/programming-9/problem-with-recursive-bash-script-538706/
# Script modified for use with all bash commands recursively
# Latest version of modified script:
# http://www.linuxdocs.nl/wiki/index.php/Recursor
a=$2
b=$3
c=$4
d=$5
e=$6
f=$7
g=$8
h=$9
do_action() {
[ -d "$1" ] || { echo "usage: recursor [directory] [bash command] [option1] [option2] [option3]" ; exit 1 ; }
# echo ; echo "$1 is a directory, now descending into it."
# enter this directory
cd "$1"
# preserve this directory name
local MYDIR="${PWD}"
$a $b $c $d $e $f $g $h
# make sure only the last part of a path is prepended;
# this also helps when an absolute path is passed as argument.
PREPEND=$(basename "$1")
for FILE in *
do
if [ -d "${FILE}" ] ; then
do_action "${FILE}"
# now exit from this directory
cd "${MYDIR}"
fi
done
}
do_action "$1"
How-TO's | Hoofdpagina | Linux Nieuws | Externe links | Help

