大网数据广告活动
服务器运维问答

Cannot run perl script with sudo

· 52CE 我爱测

I have a perl script ( test.pl ). If I run this cript by command perl test.pl , it work as normal. However, when I run command sudo perl test.pl , the error below occurs: Can't locate Log/Log4perl.pm in @INC (@INC contains: /usr/…

问题原文

原帖链接 · Waveter · CC BY-SA 3.0

I have a perl script (test.pl). If I run this cript by command perl test.pl, it work as normal. However, when I run command sudo perl test.pl, the error below occurs:

Can't locate Log/Log4perl.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .)

I think it is strange, because I run script by root. Do you know why?

已采纳解答

原帖链接 · Khaled · CC BY-SA 3.0

You may get such an error if the module you are using is not installed which seems not our case here.

The other possibility is to have a different @INC array between the two users you are running as. You can verify this using:

$ perl -V
$ sudo perl -V

Compare the output to see the different paths in @INC. You can then fix the @INC by adding the missing path or install the needed module in one of the already defined paths.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-02-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。