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: 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 | # ]