Hello Ken, seems that the problem is in fact with system() I've tried with
#my @command = ("su - $user -c id") #################################### #system ("su - $user"); #this Works# #################################### #system ("@command") == 0 or die "system @command failed: $?"; #exec ('su - $user -c $action') or print STDERR "couldn't exec foo: +$!"; #exec("/bin/su","-",$user,$action); #system ("su", "-", $user, "-c", "/bin/bash -c $action"); #system ("su - $user -c /bin/bash -c $action"); #system "sudo","su","-" => $user, -c => $action;

but each one fails!!

also i tried these modules, same result ..

use warnings; use diagnostics; use strict; use Shell::Source; use Shell; my $action="\'Anything\'"; my $user="RealUser"; my $sh = Shell->new; say "$user"; say "$action "; print $sh->sudo("su -l - $user --command $action");

I start to thinking if my Gentoo has problems , I'll try in another system...

btw I've checked for $user seems that is good, just before function.

thanks..

In reply to Re^2: run shell command as another user by ox1d0
in thread run shell command as another user by ox1d0

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.