Net::SSH sudo command hangs after entering password

前端 未结 6 1506
囚心锁ツ
囚心锁ツ 2020-12-09 13:53

I\'ve been trying to write a small library using Thor to help assist me in quick creating new projects and sites. I wrote this small method:

def ssh(cmd)
           


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 14:02

    Actually in the end, I did something very similar to Riba's suggestion (although his/her code is much better and smarter, I think)

    def ssh(env, cmd, opts={})
        Net::SSH.start( config[env]["ip"], config[env]["user"], :port => config[env]["port"]) do |session|
            cmd = "sudo #{cmd}" if opts[:sudo]
            print cmd
            session.exec cmd
        end
    end
    

提交回复
热议问题