0

im trying to automate a ssh connetcion to a NAS in order to wake up a computer using WOL. All goes fine until i try to enter the root password required for the wake command

start cmd.exe @cmd /k "ssh admin@xxx.xxx.xxx.xxx"
ping localhost -n 2
%SendKeys% "xxxxxxxxxx"
%SendKeys% "{ENTER}"
ping localhost -n 5
%SendKeys% "sudo synonet --wake xx:xx:xx:xx:xx:xx eth0"
%SendKeys% "{ENTER}"
%SendKeys% "xxxxxxxxxx"
%SendKeys% "{ENTER}"

this is the result of the above code

strange enough, the ssh password is entered correctly but calling %SendKeys% "{ENTER}" after the wake command cause strange excape characters entered causing the command to fail. Is there some way to avoid this side effects? Thanks in advance.

i tried the code above but i cannot figure out why it displays strange characters.Also other methods like putty are useless because cannot automatically enter the root password after the command.

  • Try to insert the Enter in _the same_ %Sendkeys% command: `%SendKeys% "xxxxxxxxxx{ENTER}"` – Aacini Dec 03 '22 at 13:22
  • ...and obviously ```%SendKeys% "sudo synonet --wake xx:xx:xx:xx:xx:xx{ENTER}xxxxxxxxxx{ENTER}"``` – Compo Dec 03 '22 at 14:16
  • Thanks it helps... no more strange characters displayed. But unfortunately, anyway it fails to enter the right password and since echo is off while entering passwords i cannot manage to understand what it's writing wrong. – Mind Erz Dec 03 '22 at 14:38
  • 1
    Well we need to see the rest of, i.e your deliberately omitted, code, (in order to reproduce your problem, and subsequently hep you). With what you've currently submitted, it appears from your batch file, (running in a `cmd.exe` instance), you're `start`ing a parallell `cmd.exe` instance, which then runs another permanent `cmd.exe` instance, (passing it your `ssh` command and argument). All of your commands, from line 2 onwards are not interacting with the `cmd.exe` instance running the `ssh` command. – Compo Dec 03 '22 at 15:34
  • 1
    Do this right and setup ssh keys. It is secure and it solves your problem. – Gerhard Dec 04 '22 at 06:14
  • @Compo thanks for your reply. The line 2 is a 2 seconds pause that waits for the second cmd window. Actually text is correctly sended from the first cmd windows to the second except when it comes to enter the root password. SSH password indeed s correctly inserted. – Mind Erz Dec 05 '22 at 16:51

0 Answers0