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

tail

Output the last part of a file in ruby.
linux manual

Basic Usage

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

result = host.tail('/etc/crontab', lines: 5)
result.success?
true

result.to_a
[
  [0] "17 *\t* * *\troot    cd / && run-parts --report /etc/cron.hourly",
  [1] "25 6\t* * *\troot\ttest -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )",
  [2] "47 6\t* * 7\troot\ttest -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )",
  [3] "52 6\t1 * *\troot\ttest -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )",
  [4] "#"
]

Parameters

Field Type Description
path string
Required file path to get the contents from.
bytes integer
output the last K bytes; or use +K to output starting with byte K of each file
lines integer
Output the last K lines, instead of the last 10; or use +K to output starting with line K
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 an array of the last K lines / bytes from the file, or a nil value if a file is being written to.

Exit Status

Code Description
0 Success
1 Failure

Tested On

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