Gentoo Archives: gentoo-user

From: Drew Tomlinson <drew@××××××××××××××.net>
To: Gentoo User <gentoo-user@l.g.o>
Subject: [gentoo-user] Script Run From Cron Sometimes Leaves Defunct sh Process
Date: Mon, 24 Oct 2005 07:39:30
Message-Id: 435B9FD1.2050506@mykitchentable.net
1 I wrote a script to read a smbfs mounted filesystem and make symlinks to
2 the files locally. The script appears to run fine interactively and
3 fine most of the time when run by cron. I run the script every half
4 hour. Over the course of a week or so, 15 - 20 defunct sh processes
5 show up in the ps output. I've Googled and learned that the "child" (my
6 script) is exiting but the "parent" (cron) is still around. So now my
7 question is "why" and what's wrong with my script to cause this
8 occasional behavior. And more importantly, how can I fix it? :)
9
10 Thanks for your help!
11
12 Drew
13
14 --- BEGIN ---
15 #! /bin/sh
16
17 # 10/13/05
18 # This script creates symlinks to media files on Blacklamb. Because MythTV
19 # needs to write it's own "." files and such, mounting a read-only share
20 and
21 # then creating symlinks locally keeps the share on Blacklamb clean.
22
23 remote_dir="/multimedia/Pictures"
24 local_dir="/tv/pictures"
25 find_args="-iname \"*.jpg\" -or -iname \"*.gif\""
26
27 # Don't wipe out the entire directory or else MythTV has to recreate all its
28 # local cache files. Consider using find with above $find_args to remove
29 # symlinks and avoid listing each *.xxx explicitly.
30 echo -e "\nRemoving old symlinks from $local_pictures_dir..."
31 rm "$local_pictures_dir"/*.[Jj][Pp][Gg]
32 rm "$local_pictures_dir"/*.[Gg][Ii][Ff]
33
34 # Default sh delimiter is a "space" and is stored in $IFS.
35 # This caused $original to be truncated at the first "space" in the file
36 name.
37 # Save $IFS and then set sh delimeter to a newline so 'for' loop works.
38 OLDIFS=$IFS
39 IFS='
40 '
41 echo -e "\nCreating new symlinks in $local_pictures_dir..."
42
43 # Search directory contained in $remote_dir using criteria in $find_args
44 for original in \
45 $( eval "/usr/bin/find $remote_dir \( $find_args \) -print" )
46 do
47
48 # Remove $remote_dir from filename and replace remaining "/"
49 with "-"
50 # and "spaces" with "_". Save in $newfile
51 newfile=`echo $original | cut --delimiter="/" --fields=4- | \
52 sed -e s/"\/"/-/g -e s/" "/"_"/g`
53
54 # Create symlink from original file to $newfile in $local_dir
55 # specified above.
56 ln -s "$original" "$local_dir/$newfile"
57
58 # Increase count by 1
59 count=$(( count + 1 ))
60 done
61
62 # Reset $IFS to original value
63 IFS=$OLDIFS
64
65 # Print number of symlinks created.
66 echo -e "\nCreated $count symlinks."
67
68 exit
69 --- END ---
70 --
71 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] Script Run From Cron Sometimes Leaves Defunct sh Process Heinz Sporn <heinz.sporn@××××××××.com>