小编s_o*_*_85的帖子

使用 sudo 作为另一个用户运行时的 Perl 系统调用

我开发了一个 perl 脚本,它提供了一个菜单驱动的功能,允许用户执行一些简单的任务。

我需要用户能够执行诸如复制文件(保留当前日期和权限)、以不同用户身份运行其他程序(例如 less 或 vi)等任务。该脚本大量使用了 system() 函数。我希望用户通过调用来启动菜单:

sudo -u perluser /usr/bin/perl /data/perlscripts/scripta.pl
Run Code Online (Sandbox Code Playgroud)

这应该以 perl 用户身份启动脚本,然后根据用户的选择执行不同的任务。问题是,每当我使用系统调用时,例如

system("clear");
Run Code Online (Sandbox Code Playgroud)

I get the following error

Can't exec "clear": Permission denied at /data/perlscripts/scripta.pl line 3
Run Code Online (Sandbox Code Playgroud)

If I run the script by logging in as perluser then it all runs succesfully.

Is there any way to get this working? I do not want users to be able to log in as perluser as I need to control what they are able to run. I …

linux perl redhat

2
推荐指数
1
解决办法
8449
查看次数

标签 统计

linux ×1

perl ×1

redhat ×1