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

Hi Perl Gurus,

I wanted to integrate a small shell command with perl. My main intension is to connect to remote system using ssh protocol by a normal user and switch to a previlaged user and execute commands. My shell command is :

[impact@station116 root]$ su netcool -c whoami Password: netcool [impact@station116 root]$
Can you suggest me how can I embed this part of code in my perl script.

Thanks in advance,

Srinivas.

Replies are listed 'Best First'.
Re: Integrating shell and perl
by Fletch (Bishop) on Jun 18, 2008 at 18:23 UTC
Re: Integrating shell and perl
by moritz (Cardinal) on Jun 18, 2008 at 18:25 UTC
    Use system. If you have problems with the password, consider using sudo instead of su.
Re: Integrating shell and perl
by pc88mxer (Vicar) on Jun 19, 2008 at 04:44 UTC
    My main intension is to connect to remote system using ssh protocol by a normal user and switch to a previlaged user and execute commands.
    I would consider doing this with SSH keys. You can set things up so that userA on hostA can login (without presenting a password) into hostB as userB and run a restricted set of commands. If you are embedding passwords in remote scripts, then I definitely would look at what SSH keys could do for you.

    Here is a link describing how to limit commands that can be run via ssh: The Authprogs SSH Command Authenticator.

Re: Integrating shell and perl
by chrism01 (Friar) on Jun 19, 2008 at 06:40 UTC