Skip to content

Instantly share code, notes, and snippets.

@robbyt
Created August 19, 2011 13:09
Show Gist options
  • Save robbyt/1156755 to your computer and use it in GitHub Desktop.
Save robbyt/1156755 to your computer and use it in GitHub Desktop.
Test if perl script is running as root
#! /usr/bin/perl -w
use Carp;
my $username = getpwuid($<);
my $testuser = 'root';
if ( $username eq $testuser ){
print 'yep'
} else {
croak "current user is $username need to run this as $testuser"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment