0

I am trying to create a .bat file which will create a log file that contains the list of files in a remote unix server. It runs fine when I run it manually through command prompt. But it doesn't work if I run it through 'Task Scheduler'.

The log_maker.bat file has the following lines of code in it:

PATH=%PATH%;C:\Program Files
(plink.exe -ssh username@IP -pw password -m shell_script_to_list_files.sh)>log_file.txt

Additional info:

C:\Program Files contains plink.exe

D:\path1 contains the log_maker.bat file and the shell_script_to_list_files.sh file.

TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

0
  1. To see any error message that Plink produces, redirect also an error output:

     (plink.exe -ssh username@IP -pw password -m shell_script_to_list_files.sh) > log_file.txt 2>&1
    
  2. Though you are most probably having a problem with a host key. The first SSH connection to a server requires a host key verification. If you are running your Scheduler task using a service account, it does not know your server's host key (which you have likely verified previously in your interactive account, that's why the script runs when you run it manually under your interactive account). You should add a fingerprint of the server host key to your script using -hostkey switch:

     plink.exe -ssh username@IP -pw password -hostkey aa:bb:cc... ...
    

See also the answer by @Mofi to
What must be taken into account on executing a batch file as scheduled task?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992