mirror of
https://github.com/inspec/inspec
synced 2024-11-23 21:23:29 +00:00
8155357d0a
As raised in #1526, adding an additional example showing how a user can use the `where` accessor to find commands matching a pattern and write a test using the results. Signed-off-by: Adam Leff <adam@leff.co>
68 lines
1.7 KiB
Text
68 lines
1.7 KiB
Text
---
|
|
title: About the crontab Resource
|
|
---
|
|
|
|
# crontab
|
|
|
|
Use the `crontab` InSpec audit resource to test the crontab entries for a particular user on the system.
|
|
|
|
## Syntax
|
|
|
|
A `crontab` resource block declares a user (which defaults to the current user, if not specified), and then the details to be tested, such as the schedule elements for each crontab entry or the commands itself:
|
|
|
|
describe crontab do
|
|
its('commands') { should include '/some/scheduled/task.sh' }
|
|
end
|
|
|
|
## Matchers
|
|
|
|
This InSpec audit resource has the following matchers:
|
|
|
|
### be
|
|
|
|
<%= partial "/shared/matcher_be" %>
|
|
|
|
### cmp
|
|
|
|
<%= partial "/shared/matcher_cmp" %>
|
|
|
|
### eq
|
|
|
|
<%= partial "/shared/matcher_eq" %>
|
|
|
|
### include
|
|
|
|
<%= partial "/shared/matcher_include" %>
|
|
|
|
### match
|
|
|
|
<%= partial "/shared/matcher_match" %>
|
|
|
|
## Examples
|
|
|
|
The following examples show how to use this InSpec audit resource.
|
|
|
|
### Test that root's crontab has a particular command
|
|
|
|
describe crontab('root') do
|
|
its('commands') { should include '/path/to/some/script' }
|
|
end
|
|
|
|
### Test that myuser's crontab entry for command '/home/myuser/build.sh' runs every minute
|
|
|
|
describe crontab('myuser').commands('/home/myuser/build.sh') do
|
|
its('hours') { should cmp '*' }
|
|
its('minutes') { should cmp '*' }
|
|
end
|
|
|
|
### Test that the logged-in user's crontab has no tasks set to run on every hour and every minute
|
|
|
|
describe crontab.where({'hour' => '*', 'minute' => '*'}) do
|
|
its('entries.length') { should cmp '0' }
|
|
end
|
|
|
|
### Test that the logged-in user's crontab contains a single command that matches a mattern
|
|
|
|
describe crontab.where { command =~ /a partial command string/ } do
|
|
its('entries.length') { should cmp 1 }
|
|
end
|