How can i execute 2 or more commands in the same ssh session?

前端 未结 7 1394
南方客
南方客 2021-01-06 01:14

I have the following script:

#!/usr/bin/env ruby
require \'rubygems\'
require \'net/ssh\'

Net::SSH.start(\'host1\', \'root\', :password => \"mypassword1\         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-06 01:33

    You can just give different commands separated by a new line. Something like:

    @result = ssh.exec!("cd /var/example/engines/
                        pwd
                       ")
    puts @result
    

    Its probably easier (and clearer) to pass the command to a variable, then pass the variable into exec. Same principle though.

提交回复
热议问题