Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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 '13 at 11:57
1  
Have you tried specifying full path of ssh? –  utkuerd Mar 26 '13 at 13:37

1 Answer 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.