1

Possible Duplicate:
How to successfully run Perl script with setuid() when used as cgi-bin?

I am running my Perl script as root, and would like to have these commands run as $USER

mkdir bin
cp -r /opt/gitolite .
gitolite/install -ln
gitolite setup -pk ${USER}.pub
rm ${USER}.pub

mkdir -p .gitolite/hooks/common
ln -s /opt/pre-receive .gitolite/hooks/common/

Question

Does Perl have a su -c "mkdir bin" $USER or something similar?

Community
  • 1
  • 1
Sandra Schlichting
  • 25,050
  • 33
  • 110
  • 162

1 Answers1

1

Use the special variable $> . See: http://perldoc.perl.org/perlvar.html

JoelFan
  • 37,465
  • 35
  • 132
  • 205
  • Can you give an example? I can't figure out how to use it from the link, and Google doesn't return anything useful with this. – Sandra Schlichting Nov 01 '12 at 20:21
  • 2
    Each user has a numeric uid (which you can get in the /etc/passwd file). Say user Harry has uid = 56. If your Perl script does $> = 56 then the script is now running as Harry. This will only work if your script originally started running as root. – JoelFan Nov 01 '12 at 20:43