Cannot read store key text from plink with StdoutRead

Recommended Posts

jtsteffen 0

jtsteffen 0

I have been teaching myself how to use the StdoutRead and StdinWrite commands to send and receive text from the plink program. I am trying to automate a script that logs on to a number of IP address. I was successful getting my test system to work, but then when I went to a new IP address, the script locked up. After some troubleshooting, I learned that the plink script was asking me if I wanted to store the key for the new connection (I had already done this for my test connection). If I ran plink from a command window I got this message:

"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 1040. 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)"

I could press "y" from the command window and things would work happily and give me my prompt. However if I delete the key from my computer's registry (HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys) to turn it into an unknown again, the script will not get to my prompt when I run it the next time.

I attempted to look use StdoutRead to look for this the warning text and react accordingly, but the StdoutRead never sees the text. I was able to put a Sleep command and then just StdinWrite ("y" & @CR) blindly and it was able to move past the warning text. The problem is, I don't know the quality of my connection and if I don't sleep long enough it may not wait long enough or if I put too long of a sleep, the script wil take to long to run. I want to be able to positively know when I need to send the text and send it only when I have to, when I have to.

Does anyone have any idea why I am missing the text? If so could you please give me an idea on how to fix it? I have put some of my code here. It will open a console box and attempt to use plink to connect to a server. If the IP address is already in your host list, the script will take you directly to a prompt ("~ # "). However if it is not, it will just hang, waiting.

You need to have plink.exe in the folder you save the program. Set the $vsTestIP, $vsUser, and $vsPW variables at the beginning of the script to the ones you need to use for the test.