1 Reply Latest reply on Jan 2, 2014 4:55 AM by Dude!

    grep with variable




      I am writing a script in which I use the grep command lookaround to get the value of a kernel parameter like this

      grep -Po '(?<= kernel.shmmni =).*  /etc/sysctl.conf


      Instead of writing the same commande for all kernel parameter I want to use a function in which I want to use the grep command like this


      grep -Po '(?<= var ).*  /etc/sysctl.conf


      var: is parameter of the fucnction


      How can I do it ?



        • 1. Re: grep with variable

          Where is the benefit to call a function to query individual parameters instead of the actual command if you still have to call the function for every parameter? Sorry it does not make sense to me. Perhaps you can provide a better explanation.


          There are default kernel parameters that do not need to listed in /etc/sysctl.conf. You can use the sysctl command line utility to query and maintain kernel parameters.


          For instance:


          sysctl kernel

          sysctl kernel.shmmax

          sysctl vm

          sysctl -a | grep max



          To query several entries in /etc/sysctl with one command you could use egrep and and query separate items using the pipe character, for instance:


          egrep -i 'shmmax|shmall' /etc/sysctl.conf

          You probably want to use -i to ignore case distinctions.