[ale] Question for perl gurus

Danny Cox danscox at mindspring.com
Wed Mar 5 12:33:50 EST 2003


Chris,

On Wed, 2003-03-05 at 12:18, Christopher Fowler wrote:
> I need to convert this script to perl to solve a problem that
> I do not believe bash solves.
> 
> #!/bin/sh
> 
> for i in /home/*
> do
>    U=`basename $i`
>    if [ -f ${i}/rc ]
>    then
>      echo "Starting RC script for: "${U}
>      su - ${U} -c "./rc $*"
>    fi
> done
> 
> What this simple script does is live in /etc/rc.d/init.d and looks
> at every users home directory for a file called ~/rc.  If it sees that
> file then it executes it as the user.  That file can look like this

	Well, first off, I'd use /etc/passwd to get the user names, with a
heuristic (hack) to start with user X, then use ~user to get the home
dir thereof, but that's a nit ;-)

	This is quite similar to Douglas' problem the other day.  Start the
script in the background, come back later, and if it still exists, kill
it.  Like this:

	echo "Starting RC script for: $U"
	su - "$U" -c "./rc $*" &
	PID=$!
	sleep 120
	if [ -d /proc/$PID ]
	then
		kill -KILL -- $PID  # perhaps -$PID for the whole group
	fi
	wait $PID

Of course, that solution will always wait 2 minutes between EVERY USER. 
A little more work could fork off a watcher for each rc script to be
done.  Of course, Perl could do the same thing, perhaps even easier.

-- 
kernel, n.: A part of an operating system that preserves the
medieval traditions of sorcery and black art.

Danny

_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale






More information about the Ale mailing list