wytyspy has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a perl script which does an ssh to another system for an ls of a directory. The command used in the script is: ssh computer dir /archive/myfile I recieve the message that the remote pc cmd failed. However, if I do the same command from a command line in a shell it gives me the directory listing. Why does this command work from the command line and not in the perl script? Thanks for any feedback. Lucy

Replies are listed 'Best First'.
Re: using ssh within perl script
by davidrw (Prior) on Jul 22, 2005 at 14:42 UTC
    if you run "which dir" instead of "dir /archive/myfile", what do you get from 1) perl script and 2) direct on command line on the remote machine? My first guess is that when invoked under perl it might not be processing .login (or similar) so your path or alias settings are different... Also try putting a full path to dir like "/usr/bin/dir /archive/myfile"

    Also consider (not saying it's necessary, but might help with this or future tasks) Net::SSH or similar for ssh instead of system
Re: using ssh within perl script
by ikegami (Patriarch) on Jul 22, 2005 at 15:33 UTC

    Because you're doing it wrong in the perl script? We'll try to give you a more detailed answer when you give us a more detailed question. Could you provide us with the Perl script, for starters?

    Alternatively, it could be a permission issue. Are you running the perl script from the shell, or from your web server (CGI)? If it's the latter, the script may be running as another user, which means it won't be able to access your authentication key.

Re: using ssh within perl script
by socketdave (Curate) on Jul 22, 2005 at 16:15 UTC
    This sounds like an authentication problem to me... Are you doing password auth or public key? Either way, ssh generally doesn't like taking password or passphrase input that doesn't come from a terminal.

    I also recommend that you use Net::SSH, but if you post the code you're using, we'll have a much better chance of helping you out.