<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: AWK Shell script problem in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998265#M125863</link>
    <description>here is mw awkfile:&lt;BR /&gt;BEGIN {&lt;BR /&gt;p=0&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;/^#/ {p++ }&lt;BR /&gt;{if (p==0) {print "auth.warn@mickey.msc.com "; p=2&lt;BR /&gt;}}&lt;BR /&gt;{if (p==1) p=0}&lt;BR /&gt;{print $0&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;run:&lt;BR /&gt;awk -f awkfile /etc/syslog.conf &lt;BR /&gt;and redircet the output</description>
    <pubDate>Mon, 16 Jun 2003 12:15:26 GMT</pubDate>
    <dc:creator>rachel_11</dc:creator>
    <dc:date>2003-06-16T12:15:26Z</dc:date>
    <item>
      <title>AWK Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998258#M125856</link>
      <description>Hi,&lt;BR /&gt;I would like to insert a line:&lt;BR /&gt;"auth.warn   @mickey.msc.com" into the file /etc/syslog.conf. This line is to be inserted after the first opening comment blocks:&lt;BR /&gt;#ident "@(#)syslog.conf 1.393/12/09 SMI" /* HP11.0 */&lt;BR /&gt;#&lt;BR /&gt;#&lt;BR /&gt;# syslog configuration file.&lt;BR /&gt;#&lt;BR /&gt;# This file is processed by m4 so be careful to quote (`') names&lt;BR /&gt;# that match m4 reserved words.  Also, within ifdef's, arguments&lt;BR /&gt;# containing commas must be quoted.&lt;BR /&gt;#&lt;BR /&gt;# Note: Have to exclude user from most lines &lt;BR /&gt;# so that user.alert and user.emerg are not &lt;BR /&gt;# included, because old sendmails&lt;BR /&gt;#will generate them for debugging #information.  If you&lt;BR /&gt;#have no 4.2BSD based systems doing network &lt;BR /&gt;#logging, you&lt;BR /&gt;#can remove all the special cases for "user"&lt;BR /&gt;#logging.&lt;BR /&gt;&lt;BR /&gt;Below is my script which is intended to insert the line "auth.warn   @mickey.msc.com" into the /etc/syslog.conf file. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;gawk '/#/{&lt;BR /&gt;   if(startHash==0){&lt;BR /&gt;      startHas=1;&lt;BR /&gt;   };&lt;BR /&gt;   print&lt;BR /&gt;};&lt;BR /&gt;$0 !~/#/{&lt;BR /&gt;   if(startHash==1){&lt;BR /&gt;      startHash=2;&lt;BR /&gt;      print"auth.warn   @mickey.msc.com"&lt;BR /&gt;   }&lt;BR /&gt;   else{&lt;BR /&gt;      print $0&lt;BR /&gt;   }&lt;BR /&gt;}' syslog.conf&lt;BR /&gt;&lt;BR /&gt;Unfortunately, the "auth.warn   @mickey.msc.com" does not get printed into the file /etc/syslog.conf.&lt;BR /&gt;&lt;BR /&gt;I could have done:&lt;BR /&gt;echo "auth.warn   mickey.msc.com" &amp;gt;&amp;gt; /etc/syslog.conf&lt;BR /&gt;which would place this entry at the bottom most of the file. &lt;BR /&gt;&lt;BR /&gt;However, I would like to have this entry at the very beginning of the /etc/syslog.conf i.e after the 1st comment blocks of /etc/syslog.conf.&lt;BR /&gt;&lt;BR /&gt;Could someone show me how it's to be done?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Jun 2003 10:05:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998258#M125856</guid>
      <dc:creator>Peter Remirez</dc:creator>
      <dc:date>2003-06-16T10:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: AWK Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998259#M125857</link>
      <description>if(startHash==0){ &lt;BR /&gt;startHas=1; &lt;BR /&gt;}; &lt;BR /&gt;&lt;BR /&gt;You are missing the 'h' at the end of the variable name! Therefore the variable you test (startHash) never gets set!&lt;BR /&gt;&lt;BR /&gt;Share and Enjoy! Ian&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Jun 2003 10:09:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998259#M125857</guid>
      <dc:creator>Ian Dennison_1</dc:creator>
      <dc:date>2003-06-16T10:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: AWK Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998260#M125858</link>
      <description>Hi Peter,&lt;BR /&gt;first of all there is a typo in the script (startHas=1 instead of startHash=1) which will definitely prevent it from working.&lt;BR /&gt;Secondly, as written gawk will write its output to stdout.&lt;BR /&gt;You could redirect the output to something like /etc/syslog.conf-new, and then&lt;BR /&gt;mv /etc/syslog.conf /etc/syslog.conf-old&lt;BR /&gt;mv /etc/syslog.conf-new /etc/syslog.conf&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Michael.</description>
      <pubDate>Mon, 16 Jun 2003 10:19:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998260#M125858</guid>
      <dc:creator>Michael Kelly_5</dc:creator>
      <dc:date>2003-06-16T10:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: AWK Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998261#M125859</link>
      <description>Ian,&lt;BR /&gt;Unfortunately it still did not print the line "auth.warn @mickey.msc.com" into the /etc/syslog.conf file. &lt;BR /&gt;&lt;BR /&gt;Any further ideas?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Jun 2003 10:19:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998261#M125859</guid>
      <dc:creator>Peter Remirez</dc:creator>
      <dc:date>2003-06-16T10:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: AWK Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998262#M125860</link>
      <description>Michael,&lt;BR /&gt;I tried what you suggested, but it still did not produce the result:&lt;BR /&gt;gawk '/#/{&lt;BR /&gt;   if(startHash==0){&lt;BR /&gt;      startHash=1;&lt;BR /&gt;   };&lt;BR /&gt;   ##CHANGED THIS LINE&lt;BR /&gt;   print &amp;gt; syslog.conf.1 &lt;BR /&gt;};&lt;BR /&gt;$0 !~/#/{&lt;BR /&gt;   if(startHash==1){&lt;BR /&gt;      startHash=2;&lt;BR /&gt;      #print"auth.warn          @pgldev01.png.intel.com"&lt;BR /&gt;      echo "auth.warn          @pgldev01.png.intel.com" &amp;gt;&amp;gt; syslog.conf.1 &lt;BR /&gt;  &lt;BR /&gt;      ## ADDED THIS LINE&lt;BR /&gt;      cp syslog.conf.1 syslog.conf&lt;BR /&gt;   }&lt;BR /&gt;   else{&lt;BR /&gt;      print $0&lt;BR /&gt;   }&lt;BR /&gt;}' syslog.conf&lt;BR /&gt;&lt;BR /&gt;Instead it produced the error:&lt;BR /&gt;gawk: cmd. line:5:    print &amp;gt; syslog.conf.1&lt;BR /&gt;gawk: cmd. line:5:                  ^ parse error&lt;BR /&gt;gawk: cmd. line:11:       echo "auth.warn          @pgldev01.png.intel.com" &amp;gt;&amp;gt; syslog.conf.1&lt;BR /&gt;gawk: cmd. line:11:                                                         ^ parse error&lt;BR /&gt;gawk: cmd. line:12:       cp syslog.conf.1 syslog.conf&lt;BR /&gt;gawk: cmd. line:12:                ^ parse error&lt;BR /&gt;gawk: cmd. line:12:       cp syslog.conf.1 syslog.conf&lt;BR /&gt;gawk: cmd. line:12:                              ^ parse error&lt;BR /&gt;&lt;BR /&gt;Could you show me how's to be done?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Jun 2003 10:30:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998262#M125860</guid>
      <dc:creator>Peter Remirez</dc:creator>
      <dc:date>2003-06-16T10:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: AWK Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998263#M125861</link>
      <description>#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;cat /tmp/testfile |awk 'BEGIN {found=0} found == 0 &amp;amp;&amp;amp; $0 !~ /^#/ {print "auth.warn @mickey.msc.com";print $0 ;found=1}&lt;BR /&gt;found != 0 || $0 ~ /^#/ {print $0}' &amp;gt;/tmp/testfile2&lt;BR /&gt;&lt;BR /&gt;cat /tmp/testfile2&lt;BR /&gt;&lt;BR /&gt;This code works. I think the problem was your code is too complex for the job it needs to do. Share and Enjoy! Ian&lt;BR /&gt;&lt;BR /&gt;Output from test code as follows,...&lt;BR /&gt;&lt;BR /&gt;# comment block 1&lt;BR /&gt;# end comment block 1&lt;BR /&gt;auth.warn @mickey.msc.com&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# comment block 2&lt;BR /&gt;# comment block 2a&lt;BR /&gt;&lt;BR /&gt;# comment block 3&lt;BR /&gt;# comment block 3a&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Jun 2003 10:48:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998263#M125861</guid>
      <dc:creator>Ian Dennison_1</dc:creator>
      <dc:date>2003-06-16T10:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: AWK Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998264#M125862</link>
      <description>Here is my version:&lt;BR /&gt;&lt;BR /&gt;Michael.&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;gawk '/#/{&lt;BR /&gt;if(startHash==0){&lt;BR /&gt;startHash=1;&lt;BR /&gt;};&lt;BR /&gt;print&lt;BR /&gt;};&lt;BR /&gt;$0 !~/#/{&lt;BR /&gt;if(startHash==1){&lt;BR /&gt;startHash=2;&lt;BR /&gt;print"auth.warn @mickey.msc.com"&lt;BR /&gt;# Now print the original line as well&lt;BR /&gt;print $0&lt;BR /&gt;}&lt;BR /&gt;else{&lt;BR /&gt;print $0&lt;BR /&gt;}&lt;BR /&gt;}' syslog.conf &amp;gt;syslog.conf-new&lt;BR /&gt;mv syslog.conf syslog.conf-old&lt;BR /&gt;mv syslog.conf-new syslog.conf&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Jun 2003 10:49:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998264#M125862</guid>
      <dc:creator>Michael Kelly_5</dc:creator>
      <dc:date>2003-06-16T10:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: AWK Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998265#M125863</link>
      <description>here is mw awkfile:&lt;BR /&gt;BEGIN {&lt;BR /&gt;p=0&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;/^#/ {p++ }&lt;BR /&gt;{if (p==0) {print "auth.warn@mickey.msc.com "; p=2&lt;BR /&gt;}}&lt;BR /&gt;{if (p==1) p=0}&lt;BR /&gt;{print $0&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;run:&lt;BR /&gt;awk -f awkfile /etc/syslog.conf &lt;BR /&gt;and redircet the output</description>
      <pubDate>Mon, 16 Jun 2003 12:15:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998265#M125863</guid>
      <dc:creator>rachel_11</dc:creator>
      <dc:date>2003-06-16T12:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: AWK Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998266#M125864</link>
      <description>Michael, Rachel &amp;amp; Ian,&lt;BR /&gt;&lt;BR /&gt;I tried the solution from Michael and the changes are now reflected in the /etc/syslog.conf file. &lt;BR /&gt;&lt;BR /&gt;However, the comment block beginning with "#" are not reflected in the new file or new output. &lt;BR /&gt;&lt;BR /&gt;Could anyone of you show me how I could preserve all comment blocks in the /etc/syslog.conf file once the line auth.warn    @mickey.msc.com &lt;BR /&gt;is included?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;PS: Attached is the /etc/syslog.conf file after the inclusion of the line:&lt;BR /&gt;auth.warn    @mickey.msc.com &lt;BR /&gt;&lt;BR /&gt;Note that the "#" are not present compared to the original.</description>
      <pubDate>Tue, 17 Jun 2003 08:45:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998266#M125864</guid>
      <dc:creator>Peter Remirez</dc:creator>
      <dc:date>2003-06-17T08:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: AWK Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998267#M125865</link>
      <description>try setting the firsy occurence of "print" by itself to be "print $0".&lt;BR /&gt;&lt;BR /&gt;Share and Enjoy! Ian</description>
      <pubDate>Tue, 17 Jun 2003 14:49:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-shell-script-problem/m-p/2998267#M125865</guid>
      <dc:creator>Ian Dennison_1</dc:creator>
      <dc:date>2003-06-17T14:49:40Z</dc:date>
    </item>
  </channel>
</rss>

