in reply to how to su in a script ?
And-d-d-d-d.... my “very short, but shoot-you-in-the-head before you have a chance-to-do more-damage to-the-world” response to this, is as follows: “No, the-hell, you don’t!”
Stop and think about this ... think very hard about this.
Suppose that your Gentle User is not “Alice” or “Bob,” but rather, “Eve.” Also suppose that Eve’s masquerade is perfect. You, in actual fact, have no way to know whether whoever-just-showed-up at-your-door wears a White hat (Alice) or a Black one (Eve).
Therefore, you must assume ... Black. Alice is Eve unless she can prove herself to be otherwise ... and, there is no capability for her to do so. ... Unless™ this is an intra-net application operating in a context where the “business-relative identity” of the user can, in fact, be assured, to the perfect satisfaction of the Business and of every single one of its Government Auditors.
Ergo, you basically must not seriously-contemplate doing anything at all, no matter what it is, that would presuppose the successful use of sudo, with or without(!!) the sudoers mechanism. You have no idea who the user actually is. Therefore, you simply cannot in good conscience design or deploy any sort of application that would “operate as a proxy for” ... “Eve, successfully(!!) pretending to be Alice.”
Not only do you not know that you can issue a sudo command directly, but you also do not know that you can legitimately assume the system-identity of anyone who could, legitimately, pass a sudoers test. Any competent security-auditor would quite properly reject any hypothesis that you could offer here, because:
“Eve” will succeed is provably capable of succeeding in penetrating any such system ... and the resulting disaster will have your name on it.
Therefore, it is now time to go back to the drawing board. And, if you do manage to figure-out something that works, I strongly suggest that you get your manager’s vice-president(!) to sign-off on your brainchild first. (No... This Is Not A Drill.™) “Is it really that important?” Uh huh. Yeah.)