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

Hello, I have a script that needs to regularly upload a file to a server. I'm doing this using the pscp program included with PuTTY. I construct the command and then use system($command); to run it. The script is run silently at regular intervals using a cron replacement for windows and wperl.exe. What's strange is that this worked a month ago and doesn't work anymore. If I take the command and run in a command window, everything is OK. I've tried running the command using backticks too, but nothing happens there either. Any ideas?

Replies are listed 'Best First'.
Re: system() and backticks not working
by Roger (Parson) on Jan 31, 2004 at 13:37 UTC
    What's strange is that this worked a month ago and doesn't work anymore

    Did you make any changes to the system in the last month?

    If I take the command and run in a command window, everything is OK

    Just a wild guess, perhaps you have installed some program that has changed your windows profile or something like that, so that the secure copy pscp can not pick up your private key any more? Or perhaps your PATH has been modified in the last month so your script can not pick up the pscp.exe program any more?

    I've tried running the command using backticks too, but nothing happens there either

    That would not help because your problem is most likely related to scp settings.

    The script is run silently at regular intervals using a cron replacement for windows and wperl.exe

    Did you include some debugging/logging facility in your script? Do you have a log file?

    The following are a few suggestions for tracing the problem:
    1) check the return result of system command system("pscp ....") or { open $log, ">C:\pscp.log"; print $log "Can not execute the pscp command."; close $log; exit(1); } 2) add -v (verbose) option to your pscp command to print more info. redirect output of your pscp command to a log file. system("pscp .... -v >> c:\pscp.log 2>&1");

      Thanks very much for your help - in particular your suggestion to redirect the output of pscp. It turned out that the cron replacement I was running launches programs as a different user to the current one, so when pscp was exectured it looked for a cached server key in the registry that didn't exist for that user. I changed it by going into Services and changing the 'Log On As...' options for it. The thing I changed in the last month was reinstallation of the cron replacement. Thanks again!

Re: system() and backticks not working
by exussum0 (Vicar) on Jan 31, 2004 at 16:48 UTC
    The script is run silently at regular intervals using a cron...
    Most cron managers have a way of mailing you the results. You may get an error back if you set it up, if you haven't.

    Play that funky music white boy..