简体   繁体   English

使用特定的用户身份验证从另一个Perl脚本中调用一个Perl脚本

[英]Call a perl script from another perl script with specific user authentication

I have a system script as below to display stack detail 我有一个如下的系统脚本来显示堆栈详细信息

-r-xr-xr-x. 1 bin  bin    6560 Feb 17 21:01 displayPD
[sufuser@101 bin]$ ./displayPD

Usage: ./displayPD -n node

Note (this script cannot be run as root) 注意(此脚本不能以超级用户身份运行)

I want to automate and call this in a script, which is also written with same user login. 我想自动化并在脚本中调用它,该脚本也使用相同的用户登录名编写。

But when I call it from my script using system command as below it is called as a root and script fails to execute. 但是,当我使用下面的system命令从脚本中调用它时,它被称为根用户,脚本无法执行。 how do I retain user session for execution ? 如何保留用户会话以执行?

system("/opt/SMAW/SMAWsuf/bin/displayPD -n Node03 >> /tmp/HP_Details.txt");

How can I call it as sufuser and get it executed? 如何将其称为sufuser并执行它?

If your program is running as root, you can change the real ( $< ) and effective ( $> ) UIDs of the process at will. 如果您的程序以root用户身份运行,则可以随意更改进程的实际( $< )和有效( $> )UID。 For your purpose, changing EUID is enough: 为了您的目的,更改EUID就足够了:

use v5.12;

say "euid: $>";
system('whoami');
# switch user
$> = 1000; 
say "euid: $>";
system('whoami');
# switch back
$>=$<; 
say "euid: $>";
system('whoami');

Running that script as root : root身份运行该脚本:

$ sudo perl uidtest
euid: 0
root
euid: 1000
ben
euid: 0
root

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM