0

I'm currently leveraging Ruby in a docker image to run some commands on my local Linux system via SSH and Tmux. However, this isn't feasible since I can't figure out a way to actually monitor the output of the command or even determine when the command is finished.

For example:

def execute(tmux_window, command)
    cmd = "ssh root@172.17.0.1 -i ~/.ssh/my_ssh_key "
    if tmux_window == 0 # Run outside of a Tmux window.
        cmd += command
        return `#{cmd}`
    else # run inside of specified Tmux window.
        cmd += "\"tmux send-keys -t goku:#{tmux_window} \'#{command}\' C-m\""
        `#{cmd}`
    end
end

Whatever function ends up calling this function doesn't know when it's finished. Trying to get the result by doing something like results =[backtick]#{cmd}[backtick] won't work because it's running over SSH and it'll just simply run the command and exit.

Any thoughts on how I could make this a lot more manageable?

  • It almost looks like you're trying to re-invent Ansible, only with a Ruby back-end rather than Python. – DopeGhoti Apr 30 at 18:27
  • @DopeGhoti I don't know much about Ansible other than what I've just researched; however, it looks like it does support what I'm looking for, but not sure if it's overkill. – lewlsaucengravy May 1 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.