Created
October 17, 2012 17:57
-
-
Save waffle2k/3907040 to your computer and use it in GitHub Desktop.
Simple package for ensuring that a script is run as a given user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
package Must::Run::As; | |
sub import { | |
my ($package,$user) = @_; | |
unless( $user ){ | |
$user = 'mail'; | |
} | |
die "Must run as $user\n" unless ( getpwuid( $< ) eq $user ); | |
} | |
package MAIN; | |
import Must::Run::As 'foobs'; | |
print "Running as " . getpwuid( $< ) . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment