history
Get the history of commands run on a remote server in ruby.
Basic Usage
require 'kanrisuru'
host = Kanrisuru::Remote::Host.new(host: 'centos-host', username: 'centos', keys: ['~/.ssh/id_rsa'])
result = host.history(n: 5)
result.success?
true
result.to_a
[
[0] "sysctl net.ipv4",
[1] "sysctl --all",
[2] "sysctl --all --deprecated",
[3] "sysctl net.ipv4",
[4] "echo $?"
]
Parameters
| Field | Type | Description |
|---|---|---|
| histfile |
string
|
Location of the history file. |
| delete |
integer
string
array
|
Delete specific lines from the history file. If passed as a single integer, will delete that line. With a string, -5 can be used to delete the last five lines. As an array, a range of lines can be deleted. |
| clear |
boolean
|
Clears all commands from the history file. |
| n |
integer
string
|
Get the last n commands. |
Result
If options clear or delete are present, no explicit data struct returned, only option is success?, failure?, and status to see if the program exited properly. Otherwise, returns an array of commands.
Exit Status
| Code | Description |
|---|---|
| 0 | Success |
| 1 | Failure |
Tested On
- Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES