This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

Do Ruby Remote Execution Gem Cheat Sheet

A quick reference guide for the DO Ruby gem: SSH server connections, remote command execution, file inspection, streaming uploads, and content replacements.

· Published

DO is a Ruby gem providing a clean, chainable DSL for executing commands and managing files over SSH on remote Linux servers.

Server Connection

require 'do'

# Initialize connection with SSH key authentication
server = DO::Server.new('srv1', 'node1.example.com', 'root', key: ['~/.ssh/id_rsa'])

Executing Commands

# Single command
output = server.run 'uname -a'

# Multiple command arguments
server.run 'apt-get', 'update', '-y'

# Commands with stdin prompt responses
server.run 'passwd user', 'newpassword', 'newpassword'

File Inspection & Transfers

# Check file existence
server.exist?('/etc/nginx/nginx.conf') # → true / false

# Read remote file contents
content = server.read('/etc/os-release')

# Upload local file to remote server
server.upload('/local/app.tar.gz', '/var/www/app.tar.gz')

# Download remote file to local disk
server.download('/var/log/nginx/access.log', './logs/access.log')

Remote Content Manipulation

# Replace entire content
server.replace :all, 'new configuration text', '/etc/app/config.env'

# Regex replacement
server.replace /^PORT=\d+$/, 'PORT=8080', '/etc/app/config.env'

# Append content (to bottom by default, or to top)
server.append 'export PATH=$PATH:/opt/bin', '~/.bashrc'
server.append '# Autogenerated File', '/etc/motd', :top

Interactive Prompts

# Prompt user for input
answer = server.ask 'Enter deployment tag:'

# Yes/No confirmation
if server.yes? 'Do you want to run database migrations?'
  server.run 'bundle exec rake db:migrate'
end

# Wait for enter
server.wait

Related topics