[rancid] Checking for root

Ed Ravin eravin at panix.com
Sun Jun 30 02:17:04 UTC 2013


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.

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




More information about the Rancid-discuss mailing list