in reply to Linux su twice

Hi breezykatt,

Why twice?

Your first form won't work because each call to system spawns a new, independent shell.

Whether or not it's the best architecture for one script to call another under a different user is something I can't tell without knowing more about the problem you're trying to solve. But assuming you know what you're doing and why, this should work:

system("sudo -u newuser /path/to/file") == 0 or die "system failed, \$?=$?";

Update: I believe the sudo equivalent of su - (aka su -l) is sudo -i, so if you need that, use sudo -iu newuser /path/to/file

Hope this helps,
-- Hauke D

Replies are listed 'Best First'.
Re^2: Linux su twice (updated)
by breezykatt (Acolyte) on Oct 04, 2016 at 16:49 UTC
    Thanks - just wanted to provide an update. I ended up using puppet since we had that in our lab and was able to use their method to run the necessary commands since they already had it set up to distribute the software across nodes.