Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Automating sudo actions

by merlyn (Sage)
on Jan 25, 2011 at 02:35 UTC ( #884033=note: print w/replies, xml ) Need Help??

in reply to Automating sudo actions

If you're the root on the box, set up passwordless sudo, at least for the activities of interest. Passwordless sudo will be more secure than burying your password in an Expect script, by far.

-- Randal L. Schwartz, Perl hacker

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

Replies are listed 'Best First'.
Re^2: Automating sudo actions
by rastoboy (Monk) on Jan 25, 2011 at 02:40 UTC
    Thanks for that. However, the problem is beyond the scope of merely passing the sudo password, but actually doing stuff after that. How do I "do stuff" while still maintaining the terminal? If I just execute the sudo command from a system or backticks call in Perl, that terminal vanishes instantly afterward, and my next system command executes in a new terminal, losing the sudo priviledges.
      If you want to run multiple commands in a batch, there's this thing called a script... sudo that!

      How is that different than using sudo from the command line? In my (limited) experience with *nix sudo is required to prefix each command that requires privilege. You can of course capture the output from the commands you run should you need to further process or log the results. That in addition to setting up passwordless sudo permissions ought allow you to do all you've described so far.

      True laziness is hard work
        Okok my bad, sorry. I had a feeling I wasn't asking my question right, but I couldn't put my finger on it--but you've shown me the problem. What I'd like to do is 'sudo su' or 'sudo bash' and execute system calls within that environment.

        It's not quite as asinine as it sounds--it's just the limitations I find myself working under, and it's simply not possible for me to change the environment. Actually I suppose it is a bit asinine, but I'm still intensely curious if it's possible without Expect.

        It's come up in other situations as well, such as automating tasks via Net::OpenSSH needing privilege escalation--or sudo with a password over the connection, where I need to issue a series of commands where the output of one command will determine some of the syntax of the next one. So I can't very easily just chain them up with &&'s.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://884033]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2021-11-30 12:50 GMT
Find Nodes?
    Voting Booth?

    No recent polls found