[rancid] Checking for root

heasley heas at shrubbery.net
Mon Jul 1 16:25:19 UTC 2013


Sat, Jun 29, 2013 at 10:17:04PM -0400, Ed Ravin:
> On Sat, Jun 29, 2013 at 11:18:46PM +0100, Matthew Walster wrote:
> >    On 28 June 2013 16:14, heasley <[1]heas at shrubbery.net> wrote:
> > 
> >      +eval `id | sed -e 's/(.*//'`
> >      +test "$uid" -eq 0 && echo "Do not run $0 as root!" && exit 1
> > 
> >    Would it not make more sense just to compare $UID -- that's set by the
> >    shell. Essentially, you'd end up with:
> >    if [[ $UID == 0 ]]
> 
> Not sure if every shell supports that, remember RANCID has to run in a
> lot of environments, like on Solaris systems where the /bin/sh feature set
> seems to date back to 1985.

correct.

> However, since we already need Perl to run the RANCID commands, how about
> this:
> 
>   uid=`perl -e 'print "$<\n"'`
>   test "$uid" -eq 0 && echo "Do not run $0 as root!" && exit 1
> 
that'd work, but i think $> is the variable that you want.



More information about the Rancid-discuss mailing list