1

I've searched everywhere, but I can't seem to find a solution for my issue. Probably, it is code related.

I'm trying to catch the exit code from a novell program called DXCMD, to check whether certain "drivers" are running. This is no problem in bash, but I need to write a more complex perl script (easier working with arrays for example).

This is the code:

#Fill the driverarray with the results from ldapsearch (in ldap syntax)
@driverarray =`ldapsearch -x -Z -D "$username" -w "$password" -b "$IDM" -s sub "ObjectClass=DirXML-Driver" dn | grep ^dn:* | sed 's/^....//' | sed 's/cn=//g;s/dc=//g;s/ou=//;s/,/./g'`;

#iterate through drivers and get the exit code:
foreach $driverdn (@driverarray)
{
    my $cmd = `/opt/novell/eDirectory/bin/dxcmd -user $username -password $password -getstate "$driverdn"`;
    my $driverstatus = $?>>8;
}

I've come this far; the rest of the code is written (getting the states). But the $?>>8 code always returns 60. When I copy the command directly into the shell and echo the $?, the return code is always 2 (which means the driver is running fine). In bash, the code also works (but without the >>8, obviously).

I've looked into the error code 60, but I cannot find anything, so I think it is due to my code.

How can I rectify this error? Or how can I track the error? Anyone? :)

ASGM
  • 11,051
  • 1
  • 32
  • 53

1 Answers1

2

Wrong value passed to -getstate. You didn't remove the newline. You're missing

chomp(@driverarray);
ikegami
  • 367,544
  • 15
  • 269
  • 518
  • Stupid that I didn't spot that! Thanks a lot, this was indeed the solution. Thanks a bunch for giving my perl courage back :) – Tom De Dobbeleer Apr 18 '13 at 08:06
  • Maybe the next question should be: any tips to spot this kind of errors? Surprisingly, I come from C# and Java programming, but we're spoiled with good IDE's and debuggers to spot these issues. – Tom De Dobbeleer Apr 18 '13 at 08:16
  • Generally speaking, `use strict; use warnings;`. Not in this case, though. How could Perl know whether you want a newline or now in the string you're building. – ikegami Apr 19 '13 at 03:07
  • You should use String::ShellQuote's shell_quote to build the literals. Consider what happens if the password contains a semi-color, for example. – ikegami Apr 19 '13 at 03:08
  • As I'm becoming more experienced: debugging does the trick for me. The newline is visible in the perl debugger. Thanks all for answering :) – Tom De Dobbeleer Jun 04 '13 at 14:40