首先,我会说我是 Perl 的新手。
我在将 php 参数传递给我的 perl 脚本时遇到了一些问题。该参数来自 SQL 查询。这是代码的示例和说明。
此代码用于发送 ID 并从数据库中检索用户的全名,然后将其发送到 perl 脚本,以便从 Fortinet 无线设备中删除用户。
PHP 代码
 function deleteUser($db){
  $id = $POST['param'];
  $SQLq = 'delete from users where id = ?';
  $q = $db->prepare($SQLq);
  $q->execute(array($id));
  $data = $q->fetch();
  $username = $data['user_name']; #data-type in phpmyadming : varchar
  exec('perl /var/www/xxx/deleteUserWifi.pl'.' '.escapeshellarg($id).' '.escapeshellarg($username),$output);
 }
这是我的 perl 脚本中的代码
  #!/usr/bin/perl -w
  use strict;
  use Net::SSH::Perl;
  #login info to log on the fortinet device
  my $hostname = "192.168.0.2";
  my $username = "aaaa";
  my $password = "xxxx";
  my $userID=  $ARGV[0];
  my $userName = $ARGV[1];
  #connection to the FORTINET device
  my $ssh = Net::SSH::Perl->new($hostname);
  $ssh->login($username, $password);
  #string to execute
  my $cmd  = "config vdom \n
  edit root \n
  config system dhcp server \n
  edit 2 \n
  config reserved-address \n
  delete ". $userID ." \n
  end \n
  end \n
  config firewall address \n
  delete \"" .$userName "\" \n
  end \n
  end \n
  exit"
  my($stdout,$stderr,$exit) = $ssh->cmd($cmd);
我发送我的 ID 没有问题,并从发送的 ID 中删除用户的 ip 预留。出于某种原因,我无法从设备中删除用户名条目,但如果我进入 php 代码并硬编码这样的用户名,它工作得非常好:
PHP 代码
      $username = "test test";
我在发送之前尝试过强制转换(字符串),但似乎没有任何效果。那么关于如何调试这个的任何想法???
非常感谢您提前。
种植园
PS:抱歉语法不好,英语不是我的第一语言。