* [gentoo-user] Script Run From Cron Sometimes Leaves Defunct sh Process
@ 2005-10-23 14:36 Drew Tomlinson
2005-10-24 8:04 ` Heinz Sporn
0 siblings, 1 reply; 3+ messages in thread
From: Drew Tomlinson @ 2005-10-23 14:36 UTC (permalink / raw
To: Gentoo User
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [gentoo-user] Script Run From Cron Sometimes Leaves Defunct sh Process
2005-10-23 14:36 [gentoo-user] Script Run From Cron Sometimes Leaves Defunct sh Process Drew Tomlinson
@ 2005-10-24 8:04 ` Heinz Sporn
2005-10-24 16:55 ` Drew Tomlinson
0 siblings, 1 reply; 3+ messages in thread
From: Heinz Sporn @ 2005-10-24 8:04 UTC (permalink / raw
To: gentoo-user
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: heinz.sporn@sporn-it.com
heinz.sporn@utanet.at
Website: http://www.sporn-it.com
Snail: Steyrer Str. 20
A-4540 Bad Hall
Austria / Europe
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [gentoo-user] Script Run From Cron Sometimes Leaves Defunct sh Process
2005-10-24 8:04 ` Heinz Sporn
@ 2005-10-24 16:55 ` Drew Tomlinson
0 siblings, 0 replies; 3+ messages in thread
From: Drew Tomlinson @ 2005-10-24 16:55 UTC (permalink / raw
To: gentoo-user
On 10/24/2005 1:04 AM Heinz Sporn wrote:
>Am Sonntag, den 23.10.2005, 07:36 -0700 schrieb Drew Tomlinson:
>
>
>> # 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.
>
>
Good idea!
Thanks,
Drew
--
Visit The Alchemist's Warehouse
Magic Tricks, DVDs, Videos, Books, & More!
http://www.alchemistswarehouse.com
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-10-24 17:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-23 14:36 [gentoo-user] Script Run From Cron Sometimes Leaves Defunct sh Process Drew Tomlinson
2005-10-24 8:04 ` Heinz Sporn
2005-10-24 16:55 ` Drew Tomlinson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox