@@ -, +, @@ - Create a /tmp/test.pl file containing: - Once I noticed the cronjob ran, I used mutt to read the emails in the --- debian/docs/koha-foreach.xml | 17 +++++++++++++++-- debian/scripts/koha-foreach | 11 +++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) --- a/debian/docs/koha-foreach.xml +++ a/debian/docs/koha-foreach.xml @@ -23,7 +23,7 @@ - koha-foreach | + koha-foreach | @@ -31,7 +31,20 @@ Run a command for each Koha instance. Takes the same arguments as koha-list. The string "__instancename__" is replaced in the argument list with the name of the Koha instance in each iteration. - + + + Options + + + + + This option makes the command jump into the instance's home directory before running the required command. This prevents + directory traversal permissions issues. + + + + + See also koha-create-dirs(8) --- a/debian/scripts/koha-foreach +++ a/debian/scripts/koha-foreach @@ -28,10 +28,14 @@ else exit 1 fi +chdir="no" +starting_dir=$(pwd) + listopts="" while [ ! -z "$1" ] do case "$1" in + --chdir) chdir="yes";; --email) listopts="$listopts --email";; --noemail) listopts="$listopts --noemail";; --enabled) listopts="$listopts --enabled";; @@ -53,6 +57,13 @@ do cmd=`echo "$@" | sed -e s/__instancename__/${name}/g` if [ "${cmd}" != "" ]; then + + # Change to the instance's home dir if required + [ "chdir" != "no" ] && eval cd ~$name"-koha" + koha-shell ${name} -c "${cmd}" + + # Go back to the original dir if required + [ "chdir" != "no" ] && cd $starting_dir fi done --