I wrote a script to read a smbfs mounted filesystem and make symlinks to
the files locally. The script appears to run fine interactively and
fine most of the time when run by cron. I run the script every half
hour. Over the course of a week or so, 15 - 20 defunct sh processes
show up in the ps output. I've Googled and learned that the "child" (my
script) is exiting but the "parent" (cron) is still around. So now my
question is "why" and what's wrong with my script to cause this
occasional behavior. And more importantly, how can I fix it? :)
Thanks for your help!
Drew
--- BEGIN ---
#! /bin/sh
# 10/13/05
# This script creates symlinks to media files on Blacklamb. Because MythTV
# needs to write it's own "." files and such, mounting a read-only share
and
# then creating symlinks locally keeps the share on Blacklamb clean.
remote_dir="/multimedia/Pictures"
local_dir="/tv/pictures"
find_args="-iname \"*.jpg\" -or -iname \"*.gif\""
# Don't wipe out the entire directory or else MythTV has to recreate all its
# local cache files. Consider using find with above $find_args to remove
# symlinks and avoid listing each *.xxx explicitly.
echo -e "\nRemoving old symlinks from $local_pictures_dir..."
rm "$local_pictures_dir"/*.[Jj][Pp][Gg]
rm "$local_pictures_dir"/*.[Gg][Ii][Ff]
# Default sh delimiter is a "space" and is stored in $IFS.
# This caused $original to be truncated at the first "space" in the file
name.
# Save $IFS and then set sh delimeter to a newline so 'for' loop works.
OLDIFS=$IFS
IFS='
'
echo -e "\nCreating new symlinks in $local_pictures_dir..."
# Search directory contained in $remote_dir using criteria in $find_args
for original in \
$( eval "/usr/bin/find $remote_dir \( $find_args \) -print" )
do
# Remove $remote_dir from filename and replace remaining "/"
with "-"
# and "spaces" with "_". Save in $newfile
newfile=`echo $original | cut --delimiter="/" --fields=4- | \
sed -e s/"\/"/-/g -e s/" "/"_"/g`
# Create symlink from original file to $newfile in $local_dir
# specified above.
ln -s "$original" "$local_dir/$newfile"
# Increase count by 1
count=$(( count + 1 ))
done
# Reset $IFS to original value
IFS=$OLDIFS
# Print number of symlinks created.
echo -e "\nCreated $count symlinks."
exit
--- END ---
--
gentoo-user@gentoo.org mailing list