【问题标题】:Calling bash script inside the Perl Script with system command"使用系统命令在 Perl 脚本中调用 bash 脚本”
【发布时间】:2014-03-19 21:01:32
【问题描述】:

我有一个这样的基本 shell 脚本;

#!/usr/bin/bash
echo "Openning ssh connection to remote host "$2" for "$1" user and finding the archive directory "$3""
ssh "$1"@"$2" find "$3"

我有另一个名为 Archive.pl 的 perl 脚本,在我们用 Telnet 连接连接远程服务器的脚本中。我想在这个 Perl 脚本中调用我的脚本来使用 Perl 脚本的其他模块。我正在尝试该命令,但它不起作用。

system("Connector.sh",$arg1,$arg2,$arg3);

有什么想法吗?

【问题讨论】:

  • 你确定路径吗??
  • Perl 和 bash 脚本实际上在同一路径
  • 我想你需要提到 - ./Connector.sh
  • 我需要在 Perl 脚本中进行。我不想在控制台“sh script.sh”上工作。因为在 Perl 脚本中还有其他我想要处理的模块。
  • 这样嵌套引号真的有效吗? echo "Opening ... "$2" for "$1" ...."$3""?

标签: perl bash ssh


【解决方案1】:

你可以跳过 shell 脚本,直接把它放到你的 Perl 脚本中。

print qq(Opening ssh connection to remote host "$arg2" for "$arg1" user and finding the archive directory "$arg3");
system("ssh", "$arg1\@$arg2", "find", $arg3)

【讨论】:

  • ssh: picroot: 临时名称解析失败。我收到了这个错误
  • 什么是picrootssh 连接是否在您的 Perl 脚本之外工作?
  • picroot 是用户名。是的,我可以通过控制台或我的 bash 脚本轻松连接。
  • 查看我的编辑;我忘记为调用system 切换到正确的变量。这有帮助吗?
  • 您忘记转义 @ 符号,因此将 @$arg2 插入到空字符串中,这导致 ssh 失败。由于您没有使用警告,因此您没有收到有关此严重故障的警告。教训是:永远、永远、永远使用use strict; use warnings;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-15
  • 1970-01-01
  • 1970-01-01
  • 2013-06-12
  • 2012-07-23
  • 1970-01-01
  • 2014-06-05
相关资源
最近更新 更多