|
odd recursion: calling "by hand" vs calling by cronscript...
I have a cronscript which checks (then fixes) users directories for badly named files - meaning I don't want to allow spaces or ampersands in file or directory names & it will replace spaces with underscores and removes ampersands.
If I have a directory uploaded by a user like this:
/var/pub/ftp/username/top level/second level/third level/
/var/pub/ftp/username/top level/second level/third level/pork & beans
then I call this script by typing it's name (I call it sr) in a bash shell like this:
cd /var/pub/ftp
sr
then I end up with:
/var/pub/ftp/username/top_level/second_level/third_level/ /var/pub/ftp/username/top_level/second_level/third_level/pork_beans
the program works by parsing directories then recursively calling itself to descend further until it has fix all files and directories below the directory it has been called.
I set it to run in a cronscript, and get different results! Here is what I get when it is called by cron:
/var/pub/ftp/username/top_level/second_level/third level/
/var/pub/ftp/username/top_level/second_level/third level/pork & beans
so, it doesn't successfully call itself when started by cron.
Here is the script for sr (called that originally for space replace)
and if you can give me a hint why this might be happening, I would be very grateful.
I just don't get why the recursion works when typed into bash, but not when called by cron
Running FC2, btw.
The cronjob belongs to root.
----
for i in *
do
if [ -d "$i" ] # if * is a directory
then
cd "$i" # descend into the directory
for y in *
do
tempa=$(echo $y | sed 's/ /_/g' | sed -e 's/\&//g' | sed 's/__/_/g')
wait
if [ "$y" != "$tempa" ]
then
mv "$y" "$tempa"
wait
fi
if [ -d "$tempa" ] # if this is also a directory, call this program
then
cd "$tempa"
sr # this is the name of THIS program, must be in your PATH
wait
cd ..
fi
done
cd ..
fi
tempa=$(echo $i | sed 's/ /_/g' | sed -e 's/\&//g' | sed 's/__/_/g')
wait
if [ "$i" != "$tempa" ]
then
mv "$i" "$tempa"
wait
fi
done
Thanks for you help,
Paul in Colorado
Last edited by prx; 02-12-2005 at 10:28 AM.
|