write a shell script to ssh to a remote machine and execute commands

后端 未结 9 1377
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 19:11

I have two questions:

  1. There are multiple remote linux machines, and I need to write a shell script which will execute the same set of commands in each machine.
9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 19:37

    You can follow this approach :

    • Connect to remote machine using Expect Script. If your machine doesn't support expect you can download the same. Writing Expect script is very easy (google to get help on this)
    • Put all the action which needs to be performed on remote server in a shell script.
    • Invoke remote shell script from expect script once login is successful.

提交回复
热议问题