2016-09-22 12:43:57 +00:00
|
|
|
---
|
|
|
|
title: About the bash Resource
|
|
|
|
---
|
|
|
|
|
|
|
|
# bash
|
|
|
|
|
|
|
|
Use the `bash` InSpec audit resource to test an arbitrary command that is run on the system using a Bash script.
|
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
<br>
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
## Syntax
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
A `command` resource block declares a command to be run, one (or more) expected outputs, and the location to which that output is sent:
|
|
|
|
|
|
|
|
describe bash('command') do
|
|
|
|
it { should exist }
|
2018-02-01 10:51:12 +00:00
|
|
|
its('property') { should eq 'output' }
|
2016-09-22 12:43:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
where
|
|
|
|
|
|
|
|
* `'command'` must specify a command to be run
|
|
|
|
* `'matcher'` is one of `exit_status`, `stderr`, or `stdout`
|
|
|
|
* `'output'` tests the output of the command run on the system versus the output value stated in the test
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
describe bash('ls -al /') do
|
|
|
|
its('stdout') { should match /bin/ }
|
|
|
|
its('stderr') { should eq '' }
|
|
|
|
its('exit_status') { should eq 0 }
|
|
|
|
end
|
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
<br>
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
## Matchers
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2018-01-31 12:24:16 +00:00
|
|
|
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### exist
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
The `exist` matcher tests if a command may be run on the system:
|
|
|
|
|
|
|
|
it { should exist }
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### exit_status
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
The `exit_status` matcher tests the exit status for the command:
|
|
|
|
|
|
|
|
its('exit_status') { should eq 0 }
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### stderr
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
The `stderr` matcher tests results of the command as returned in standard error (stderr):
|
|
|
|
|
|
|
|
its('stderr') { should eq '' }
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
### stdout
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
The `stdout` matcher tests results of the command as returned in standard output (stdout).
|
|
|
|
|
|
|
|
its('stdout') { should match /bin/ }
|