This is the development version of Kanrisuru. Since this is still a pre-1.0 release, we don't recommend using this in system-critical production environments.

Kanrisuru

echo

Display a line of text in ruby.
linux manual

Basic Usage

require 'kanrisuru'
host = Kanrisuru::Remote::Host.new(host: '127.0.1.1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])

result = host.echo('hello world')
result.success?
true

result.to_s
"hello world"

Parameters

Field Type Description
text string
Required content to output to the remote machine
backslash boolean
Enable interpretation of backslash escapes, ie: \n, \t, \r, etc.
mode string
Can be either append or write options. Determines how content is saved into a file.
new_file string
The name of the newfile to write the content to

Result

Either returns a echoed version of original string, or a nil value if a file is being written to.

Additional Examples

host.env['VAR'] = 'world'
result = host.echo("hello\n$VAR", mode: 'write', new_file: 'test.txt')
result.success?
true

host.cat('~/test.txt', lines: 3).to_a
[
  "hello",
  "world"
]

result = host.echo('more text', mode: 'append', new_file: 'test.txt')
result.success?
true

host.cat('~/test.txt').to_a
[
  "hello",
  "world",
  "more text"
]

Exit Status

Code Description
0 Success
1 Failure

Tested On

  • Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES