1

I have simple powershell script which gets the offset of a Ubuntu server with the time of the NTP server.

The command I run is

$result = ssh -i C:\temp\privatekey domain\username@servername "ntpdate -q 192.168.10.1"

When I run this script manually the $result variable is populated as expected. When I run as a scheduled task (as the same user) the script does not set the $result variable at all leaving it blank.

Is there further options I need to enter as part of the SSH command or as part of the scheduled task calling the ps script? Any help very much appreciated.

2
  • I have just used a try catch to check what is happening and I am getting an error saying that "ssh is not recognized as the name of a cmdlet"
    – user166435
    Mar 26, 2013 at 11:57
  • 1
    Have you tried specifying full path of ssh? Mar 26, 2013 at 13:37

1 Answer 1

1

When you run a command from the command line, your entire environment, including your $PATH variable, is available to the command. When it's run from a scheduler, e.g. cron, that's not the case.

So when you write scripts that will be run from any type of schedulare, you should make sure to always include the full path to all commands in the script, or else to start by giving the script a proper $PATH setting.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .