Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Runs As Root' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Runs As Root
Authored by: escowles on Jan 16, '03 04:52:11PM

Too bad this runs as root, not as the user who's logging in/out. I even setup a script to see if the ownership for console was changed (it's not) or if there's anything in the environment that tells you which user it is (there isn't).

Does anybody know how to tell which user is logging in/out?

-Esme



[ Reply to This | # ]
Runs As Root
Authored by: pmccann on Jan 16, '03 05:54:11PM

Hmm, not sure what the state of play is when this script is run (ie, is the user still logged in and about to be logged out?), but if he or she is still listed as logged in you should be able to use something as simple as

who | grep console | cut -f 1 -d ' '

If the user is gone then all bets are off. Looking at the developer page linked to the original story I'm unfortunately going to have to bet on the latter ("-LogoutHook The full path to a script or tool to run when a user successfully logs out.") There: not *completely* useless am I? Errr...

Cheers,
Paul



[ Reply to This | # ]
Runs As Root
Authored by: bjjessup on Jan 16, '03 09:43:44PM

You can run a command as the user who logged in using the bash variable $1.

for instance chown $1 /Users/$1

will change the ownership of the logged in users home directory to themselves.



[ Reply to This | # ]
Runs As Root
Authored by: escowles on Jan 17, '03 10:37:33AM

Thanks for pointing this out. Once you've got the username, it's pretty easy to setup what I'd really like: getting a shell script to run at login. You can make an AppleScript to do this, but I would rather that it happen silently and for all users who create the appropriate script in their home dir.

The following is a Perl script that will run $USER/bin/LoginScript when they login -- it will run the script as that user, not as root:

---------- CUT HERE ----------
#!/usr/bin/perl

$user = $ARGV[0];
@UINFO = getpwnam( $user );
$home = $UINFO[7];
$script = "$home/bin/LoginScript";

if ( -x $script )
{
exec( "su - $user -c $script" );
}
---------- CUT HERE ----------



[ Reply to This | # ]
Runs As Root
Authored by: inode on Mar 08, '03 06:03:54AM

echo $LOGNAME



[ Reply to This | # ]