0

How do I check if the first line of the file contains a certain string using Inspec test? Currently, I am doing this.

describe file ('/path/to/file/filename')do
  it { should exist }
  its('content') { should match 'build/path/location' }
 end
end

How can I make it better not to check the whole content but only the first line?

Matthijs van der Veer
  • 3,865
  • 2
  • 12
  • 22

1 Answers1

0

To check the file content (Eg.: rsyslog.conf) were content should be *.=/var/log/debug.log

Then the following Module will help you to test it.

   control "rsyslog-1-2-2" do
      impact 1.0
      desc "Checking Inside rsyslog configuration File & checking the Application Logs Conf. has been set it up."
      describe file("/etc/rsyslog.conf") do
        its('content') { should match(%r{^\*.=debug\s.*?/var/log/debug.log}) }
      end
    end
Bala
  • 29
  • 3