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

Thanks for your replies

Let me try to explain the problem more clearly.
1. Say i want to execute 5 commands in a remote server.These commands are owned in a generic user id.
2. This should be executed one after the other. Output of one command execution is used as input to the second command.
3. I was using Net::SSH module to execute command in remote server( Why Net::SSH ? - using this i will get exit status,output and error status as return values). Once the remote connection is established, i need to be in generic user id (here i need to do sudo su "userid" )to execute the commands.

This is the problem i am trying to solve.

Meanwhile i will check on IPC::ShellCmd.

Thanks, Riju

Replies are listed 'Best First'.
Re: Implementing Unix sudo command in Perl
by robby_dobby (Hermit) on Mar 19, 2014 at 07:33 UTC
    Hello rijuroyson,

    Your problem statement is vague enough for me not to be able to give you concrete information. :-) Just by going through your question, your problem looks a lot like a job for IPC::ShellCmd and its allied modules. For instance, to implement sudo su $generic_user_id, you can use IPC::ShellCmd::SSH and then you can chain further commands to be executed:

    # build your ShellCmd obj - $shellcmd and the command to execute my $shellcmd = IPC::ShellCmd->new($mycommand_to_run); $shellcmd->chain_prog( IPC::ShellCmd::SSH->new( User => 'genericuser', Host => $myhost ) ); $shellcmd->run();
    There's even a full example on the module page IPC::ShellCmd.

    Hope this helps.

Re: Implementing Unix sudo command in Perl
by hdb (Monsignor) on Mar 19, 2014 at 07:39 UTC

    Long ago are the times of me using Unix but I seem to remember something called setuid whereby you can assign the rights of the file owner to the user executing it. Would this alternative be helpful to you?