Ask Your Question
0

invalid as number of arguments for sub in awk

asked 2015-02-28 11:49:43 -0500

Chutki gravatar image

Hi,

I have issue to execute awk statment in puppet

Pls find below manifests

define semmns_val($value) {
  exec { 'semmns':
    cwd     => '/etc',
    path    => ['/etc'],
    command => "/usr/bin/awk '/kernel.sem/ { if(($3 + 0) < $value) sub($3, $value) } 1' /etc/sysctl.conf >> /etc/sysctl.conf.mod",
    logoutput => on_failure
    }
    }

In sysctl file, there is no value for kernel.sem. I manually added that for testing below is the value that I added

kernel.sem = 250     32000   32      128

But when I execute I am getting below error message

Notice: /Stage[main]/Sysctl/File[/etc/sysctl.conf]/content:
--- /etc/sysctl.conf    2015-02-28 02:05:21.752986382 -0500
+++ /tmp/puppet-file20150228-4647-1xnmj5k       2015-02-28 02:05:46.237032886 -0500
@@ -49,7 +49,4 @@
 net.ipv4.conf.default.accept_redirects = 0
 net.ipv4.conf.all.accept_redirects = 0
 net.ipv4.conf.default.send_redirects = 0
-
-kernel.sem = 250     32000   32      128
 ##Hardening
-
Info: /Stage[main]/Sysctl/File[/etc/sysctl.conf]: Filebucketed /etc/sysctl.conf to puppet with sum c2940b18920b926aac7010ef858925e9
Notice: /Stage[main]/Sysctl/File[/etc/sysctl.conf]/content: content changed '{md5}c2940b18920b926aac7010ef858925e9' to '{md5}251f5a39012b056c97f1ae1b95c92562'
Notice: /Stage[main]/Infappsysctl::Kersem/Infappsysctl::Kersem::Semmns_val[kernel_semmns]/Exec[semmns]/returns: awk: /kernel.sem/ { if(( + 0) < 700) sub(, 700) } 1
Notice: /Stage[main]/Infappsysctl::Kersem/Infappsysctl::Kersem::Semmns_val[kernel_semmns]/Exec[semmns]/returns: awk:                                     ^ syntax error
Notice: /Stage[main]/Infappsysctl::Kersem/Infappsysctl::Kersem::Semmns_val[kernel_semmns]/Exec[semmns]/returns: awk: fatal: 0 is invalid as number of arguments for sub
Error: /usr/bin/awk '/kernel.sem/ { if(( + 0) < 700) sub(, 700) } 1' /etc/sysctl.conf >> /etc/sysctl.conf.mod returned 2 instead of one of [0]
Error: /Stage[main]/Infappsysctl::Kersem/Infappsysctl::Kersem::Semmns_val[kernel_semmns]/Exec[semmns]/returns: change from notrun to 0 failed: /usr/bin/awk '/kernel.sem/ { if(( + 0) < 700) sub(, 700) } 1' /etc/sysctl.conf >> /etc/sysctl.conf.mod returned 2 instead of one of [0]

Also the value what I added "kernel.sem = 250 32000 32 128" was missed form the sysctl.conf

I am suscpecting "+++ /tmp/puppet-file20150228-4647-1xnmj5k 2015-02-28 02:05:46.237032886 -0500" is updating sysctl.conf file, if it is so what this tmp/puppet file does.

I guess, due to missing "kernel.sem" that is the reason the awk statement fails since it could not file any value in column 3 for kernel.sem.

but when I run this "/usr/bin/awk '/kernel.sem/ { if(($3 + 0) < 700) sub($3, 700) } 1' /etc/sysctl.conf >> /etc/sysctl.conf.mod" separately in command prompt, it worked fine.

I am clueless to find out the cause, it is purely my guess.

edit retag flag offensive close merge delete

Comments

These are really awk-related questions, not Puppet. If you want to use exec+awk and have trouble with the awk command, it's probably best to ask on Stackoverflow to get the best answers. I would encourage you to try to solve this with a native Puppet solution, though, and we can help with that.

GregLarkin gravatar imageGregLarkin ( 2015-03-04 19:20:51 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-03-02 11:32:33 -0500

Chutki gravatar image

updated 2015-03-02 11:34:36 -0500

sysctl module is present in another directory. That is the reason file got updated and kernel.sem was missed.

Also below /$3 resolved my awk issue

command => "/usr/bin/awk '/kernel.sem/ { if((/$3 + 0) < $value) sub(/$3, $value) } 1' /etc/sysctl.conf >> /etc/sysctl.conf.mod",
edit flag offensive delete link more
0

answered 2015-02-28 14:08:50 -0500

doc75 gravatar image

Somewhere in your manifests (or in a module you rely on), there is ressource describing the file /etc/sysctl.conf. This resource update the file at every run and overwrite your manual modification. You have to find who is managing this Sysctl class (if I understand well the traces you put).

Hope this helps.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-02-28 11:49:43 -0500

Seen: 289 times

Last updated: Mar 02 '15