Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created October 17, 2012 17:57
Show Gist options
  • Save waffle2k/3907040 to your computer and use it in GitHub Desktop.
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
#!/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