#! /usr/bin/perl # put into the public domain by Russell Nelson # NO GUARANTEE AT ALL; support is available for a fee from the author. # # executes the rest of the command line as each user. while(($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwent()) { next unless $dir =~ m!^/home!; if (!-e $dir) { warn "warning: ${name}'s home dir, $dir, doesn't exist, skipping.\n"; next; } $st_uid = (stat($dir))[4]; if ($uid != $st_uid) { warn "warning: $name is $uid, but $dir is owned by $st_uid, skipping.\n"; next; } if ($pid = fork()) { die "fatal: failed to fork\n" if $pid < 0; waitpid($pid, 0) or die "fatal: command failed for $name\n"; } else { $< = $> = $uid; $( = $) = $gid; $ENV{USER}=$name; $ENV{HOME}=$dir; chdir($dir); exec @ARGV; } } endpwent();