[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

My Network Configuration



We have a couple of scripts that need to be run as root.

#!/bin/sh -f
USER=`id | sed -e "s/\(.[^(]*(\)\(.[^)]*\)\(.*\)/\2/"`
if [ "root" != "$USER" ]; then
   echo "$0: must be run as root."
   exit 1
fi

Decoding that sed argument could take a while. Note the single quote is 
a back tick.

In a PERL script

#!/usr/bin/perl
use strict;
my ($name, $pw, $uid, $gid, $quota, $comment, $gcos, $dir, $shell);
($name, $pw, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = 
getpwuid $> ;
if ($name ne "root") {
   printf STDOUT "Must be run as root.\n";
   exit 1;
}

-- 
David M. Dunbar <ddunbar@geocenter.com>
Verus meminissat nemo. Falsus obliviscat nemo.
When you are right, nobody remembers.
When you are wrong, nobody forgets.