【问题标题】:execution of system command from perl script using su使用 su 从 perl 脚本执行系统命令
【发布时间】:2016-01-08 08:55:47
【问题描述】:

我有一个 perl 脚本如下: 测试.pl

 #!/usr/bin/perl
 system("ls -lart");

这很好,但是当我按如下方式运行它时它失败了:

su guest test.pl

它在第二行失败,如下所示:

0403-057 Syntax error at line 2 : `(' is not expected.

【问题讨论】:

    标签: perl ksh


    【解决方案1】:

    来自man 1 su

    OPTIONS
           The options which apply to the su command are:
    
           -c, --command COMMAND
               Specify a command that will be invoked by the shell using its -c.
    
               The executed command will have no controlling terminal. This option cannot be used to execute interractive programs which need a controlling TTY.
    

    所以你应该使用

    su -c "perl /path/to/test.pl --maybe some.options" guest
    

    【讨论】:

      【解决方案2】:

      您必须使用su-c 选项来执行它。问题是,如果你这样启动它,它应该是一个 shell 脚本。所以你必须告诉su实际加载shell然后执行命令。

      很有可能

      su guest -c test.pl
      

      会起作用(当然,前提是它在用户的命令路径中)。

      【讨论】:

        猜你喜欢
        • 2013-06-12
        • 2012-10-20
        • 1970-01-01
        • 1970-01-01
        • 2017-03-15
        • 2012-07-21
        • 2014-03-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多