简体   繁体   English

在Linux服务器中执行Perl文件时某些文件夹的权限错误

[英]Permission error for certain folders while executing a perl file in Linux server

I am executing a perl file in Linux server for automation scripts. 我正在Linux服务器中为自动化脚本执行perl文件。 It would be of great help if you could help on this. 如果您能对此有所帮助,那将是极大的帮助。

My current server is a two node cluster server and I am using perl automation scripts. 我当前的服务器是一个两节点群集服务器,我正在使用perl自动化脚本。 I dont want to copy my perl file to both the nodes so I want to execute the command remotely using "ssh" command to the second node. 我不想将我的perl文件复制到两个节点,所以我想使用“ ssh”命令远程执行命令到第二个节点。 My node 1 server is abd01 and my node 2 server is abd02. 我的节点1服务器是abd01,而我的节点2服务器是abd02。 I have logged into abd01 and running a remote command for abd02. 我已经登录到abd01并为abd02运行远程命令。 Below is my command : 下面是我的命令:

ssh -q abd02 "ls -lh \$(find \-L \/opt\/emageon\/backup\/\${UNIQUE_CUSTOMER}*/\$(date '+%Y%m%d') -type f)|grep sfdisk___sr0 | awk 'END {print NR}'"

I get an output value of "8" for this. 为此,我得到的输出值为“ 8”。

I am using the same command in a perl file along with the escape characters and when I run the perl file with the command "perl icount.pl" I do not get the desired output. 我在perl文件中使用相同的命令以及转义符,并且当我使用命令“ perl icount.pl”运行perl文件时,没有得到所需的输出。 Below is the perl script of icount.pl file that i am using 下面是我正在使用的icount.pl文件的perl脚本

#!/usr/bin/perl
use strict;
use warnings;
use Config;
use Socket;
use POSIX qw(strftime);
use IO::Socket::INET;


my $icount;
$icount = `ssh -q root\@rcs02 \"ls -lh \$(find -L /opt/emageon/backup/\${UNIQUE_CUSTOMER}*/\$(date \'+%Y%m%d\') -type f)|grep sfdisk___sr0 | awk 'END {print NR}'"`;

print "Value is $icount /n";

The output that I get for this is as mentioned below; 我得到的输出如下所示;

Value is -rw-r----- 1 druser druser 3.1M Mar  4 01:59 /opt/emageon/backup/0050569143c5/20160304/drbackup/info/drosbackup.sh.log
0

For most of the files I am getting messages as shown below 对于大多数文件,我收到如下所示的消息

bash: line 126: /opt/emageon/backup/005056916d4d/20160304/scbackup/DARC/201603040416/controlfile.txt: Permission denied bash:第126行:/opt/emageon/backup/005056916d4d/20160304/scbackup/DARC/201603040416/controlfile.txt:权限被拒绝

I am really not sure why I am not getting the output of 8 when I am running the same command in perl file. 我真的不确定为什么在perl文件中运行相同命令时为什么没有得到8的输出。 Please help me on this as I am stuck amidst my automation scripts 请帮助我,因为我陷入了自动化脚本中

Try using qx{} instead of the backtick operator. 尝试使用qx{}代替反引号运算符。 In particular you can use qx' ...' . 特别是,您可以使用qx' ...' Using single-quote as a delimiter protects the command from Perl's double-quote interpolcation, passing it on to the shell instead. 使用单引号作为定界符可以保护命令免受Perl的双引号插值的影响,而会将其传递给Shell。

You can omit the single quotes for the date format, they are not required. 您可以省略日期格式的单引号,这不是必需的。

And you can replace the awk script with wc -l . 您可以用wc -l替换awk脚本。

Also you are using ls together with find . 另外,您将lsfind一起使用。 Usually "find" by itself is enough. 通常,仅凭“查找”就足够了。 Checkout the -printf option in the find man page. find手册页中检出-printf选项。 It can print the user name of the owner and much more. 它可以打印所有者的用户名等等。 You can also use find to restrict the result to things owned by a particular user. 您还可以使用find将结果限制为特定用户拥有的东西。

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

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