Vishza has asked for the wisdom of the Perl Monks concerning the following question:

I am new to perl and have been trying a test script to perform a simple task by connecting to the root user and executing a command. I have not been very successful in this. Please assist. I have below: the sudoers file as well as my code piece. the test.log has no data in it.


# User alias specification User_Alias ROOT_ALLOW_SU=<myuser>
# Cmnd alias specification
# Defaults specification
# Runas alias specification
# User privilege specification
root ALL=(ALL) ALL
ROOT_ALLOW_SU ALL = NOPASSWD: /usr/local/bin/suroot
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
# Samples
# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users localhost=/sbin/shutdown -h now
I run the following in perl and my file is not populated:  system('sudo suroot -i /usr/bin/df -k > test.log');

Replies are listed 'Best First'.
Re: sudo not working
by ww (Archbishop) on Dec 24, 2014 at 15:22 UTC

    Is the code you've shown you whole program? If so, why bother Perl with system requests?

    Is the unformatted list beginning "#User alias...." supposed to be the content of your "sudoers" file as implied by the narrative and, if so, why isn't it formatted in code tags as explicitly mentioned in the markup directions at the text box you used to create your question?

    Why does this look like an attempt to upgrade unauthorized users/processes to perform (malicious?) actions with root's credentials? (It sure as hell doesn't look like a reasonable exercise for a Perl noob!)

      Thanks, for the replies and pointing me in the direction of the issue.
      I am not trying to do any malicious work here but rather trying to perform health checks on a system for 2 different users, I was trying to avoid asking the user for both passwords. Thanks I have found another way of doing it.

Re: sudo not working
by Anonymous Monk on Dec 24, 2014 at 13:55 UTC
    Not a Perl question. Your sudoers file is wrong and your shell command is wrong too. Read man sudo and man sudoers. And what is suroot? Maybe it's just me but I never heard of it.