Поставлена задача, автоматизировать копирование файлов с отчетами с терминального сервера Linux на компьютер пользователя на Windows.

Создаем bat файл следующего содержания:

@echo off

set rdpuser=»имя учетной записи в linux»
set rdppassword=»пароль учетной записи в linux»

mkdir C:\image_status\folder1
mkdir C:\image_status\folder2
mkdir C:\image_status\folder3
mkdir C:\image_status\folder4

ECHO «Y» | C:#monitoring\image_status_script\pscp.exe -P 22 -pw %rdppassword% %rdpuser%@10.0.0.222:/opt/monitoring/image_status/folder1/.status.images C:\image_status\folder1
ECHO «Y» | C:#monitoring\image_status_script\pscp.exe -P 22 -pw %rdppassword% %rdpuser%@10.0.0.222:/opt/monitoring/image_status/folder2/.status.images C:\image_status\folder2
ECHO «Y» | C:#monitoring\image_status_script\pscp.exe -P 22 -pw %rdppassword% %rdpuser%@10.0.0.222:/opt/monitoring/image_status/folder3/.status.images C:\image_status\folder3
ECHO «Y» | C:#monitoring\image_status_script\pscp.exe -P 22 -pw %rdppassword% %rdpuser%@10.0.0.222:/opt/monitoring/image_status/folder4/.status.images C:\image_status\folder4

Поскольку bat файл нужно было добавить в планировщик Windows, столкнулся с тем, что при запуске скрипта он висел, но не выполнялся. Чтобы понять причину, снял галочку Скрытая задача, чтобы увидеть глазами весь цикл выполнения кода, а так же добавить timeout после каждого блока

Текст:

The server’s host key is not cached in the registry. You have no guarantee that the server is the computer you think it is.
The server’s rsa2 key fingerprint is:
ssh-rsa 2048 ef:2d:28:f6:d1:e3:7a:46:40:29:da:8b:86:ae:dd:60
If you trust this host, enter «y» to add the key to PuTTY’s cache and carry on connecting.
If you want to carry on connecting just once, without adding the key to the cache, enter «n».
If you do not trust this host, press Return to abandon the connection.
Store key in cache? (y/n)

Оказалось, что нужно было каждый раз подтверждать ключ хоста. Для этого перед командой pscp.exe, чтобы она не запрашивала подтверждение добавляем ECHO "Y" |

Тогда задача в планировщике выполняется без ошибок и остановок.

P.S. Как добавлена задача

Добавить комментарий

Ваш адрес email не будет опубликован.