#!/usr/bin/perl -w # # userinit: utility to run user commands on startup # $MIN_USER_ID = 500; $USER_INIT_FILE = ".userinit"; $verbose = 1; use FileHandle; my $fin = new FileHandle(") { my($user,undef,$uid,$gid,undef,$home,$shell) = split /:/; if($uid < $MIN_USER_ID) { next; } if(-f "$home/$USER_INIT_FILE") { my(undef,undef,undef,undef,$f_uid,$f_gid,undef) = stat("$home/$USER_INIT_FILE"); # # Conduct some general paranoia checks. # if($f_uid != $uid) { if($verbose) { print STDERR "File not owned by user: $user" } next; } if($f_gid != $gid) { if($verbose) { print STDERR "File not owned by $user\'s group" } next; } # # Execute the command under a login shell, piped to mail # system("/bin/su - $user -c \"source $home/$USER_INIT_FILE | mail $user -s 'userinit output'\""); } } $fin->close();