Am Sonntag, den 23.10.2005, 07:36 -0700 schrieb Drew Tomlinson:
> 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"
Just a suggestion: insert a minimum of error handling like
ln -s "$original" "$local_dir/$newfile"
if (( $? > 0 )) ; then logger -t "myscript" "That didn't work for some
reason ; fi
... or something else at points where the script could fail.
>
> # 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 ---
--
Mit freundlichen Grüßen
Heinz Sporn
SPORN it-freelancing
Mobile: ++43 (0)699 / 127 827 07
Email: [EMAIL PROTECTED]
[EMAIL PROTECTED]
Website: http://www.sporn-it.com
Snail: Steyrer Str. 20
A-4540 Bad Hall
Austria / Europe
--
[email protected] mailing list