1

I am trying to log into a linux node using a shell script for which I have the username and password. So i want to run a few commands on that server and then I need to capture that output and I need to show it on a HTML page.

Now firstly I am facing issues with login into the server using a shell script (I even tried .BAT file), so need help regarding it.

My incomplete script is as below:

@echo off 
cls
ssh username@xxxx.com@nodename01.xxx.xxx.xxx01.xxx.com
pause

I need to enter the password when it asks in next step and also need to hit enter after it. Also after login need to pass 'Yes' when I log in for the first time.

Any help is appreciated in advance.

Toto
  • 89,455
  • 62
  • 89
  • 125
Satyajit
  • 152
  • 10
  • Both "shell" and "script" apply to many shells. Which do you actually target? You write about .BAT (meaning Windows cmd.exe?) but you tagged your question with "bash". In any case, "I am facing issues" is not really a good description of those issues. Please read [ask], in case you haven't already. – Ulrich Eckhardt May 06 '21 at 16:45
  • As far as I remember, `ssh` does not accept a password from stdin, and it does not have an parameter/option to pass one to it, therefore you'll need something like `sshpass` – Compo May 06 '21 at 16:52
  • https://stackoverflow.com/questions/28197540/best-way-to-script-remote-ssh-commands-in-batch-windows – tink May 06 '21 at 17:44
  • https://stackoverflow.com/questions/14989326/batch-script-to-connect-via-ssh-execute-a-command-and-pass-the-results-to-an-ou – tink May 06 '21 at 17:45

1 Answers1

1

before run the script, you should gen ssh-key

ssh-keygen

Then run this command

ssh-copy-id 192.168.10.10
ssh-copy-id {host IP}

then run your script