in reply to Automating sudo actions

try this:
#!/usr/bin/perl # /home/zengargoyle/sudotest.pl exec '/usr/bin/sudo', '/bin/bash', '-c', $0 unless exists $ENV{SUDO_US +ER}; # if not angsty sysadmins vs sudo commands use this. # exec '/usr/bin/sudo', $0 unless exists $ENV{SUDO_USER}; print "hello from root\n"; system 'ls';
chmod +x it.
$ cd / $ /home/zengargoyle/sudotest.pl [sudo] password for zengargoyle: hello from root auto dev initrd.img.old mnt ... ... $

Replies are listed 'Best First'.
Re^2: Automating sudo actions
by rastoboy (Monk) on Jan 27, 2011 at 00:15 UTC
    Thanks tilly and zentara for the great explanations. I'm feeling a little more educated now :-)

    Thanks for the other tricks from the other folks as well!