Search code examples
regexrspecserverspecinspec

Use a regex to check cron entry '0 5 * * * /usr/bin/aide --check'


How do I check the cron entry 0 5 * * * /usr/bin/aide --check with a regex? I would like to check this in Chef InSpec like

its('content') { should match /<the regular expression>/ }

Solution

  • describe cron do
      it { expect(subject).to have_entry '0 5 * * * /usr/bin/aide --check' }
    end
    

    is the proper way to do this in Serverspec and will also solve your problem with formatting immediately.

    If you really wanted to use a regexp (and your followup comment left as an answer implies you don't), then you could do:

    its(:content) { is_expected.to match %r{0 5 \* \* \* /usr/bin/aide --check} }