<?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: shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/5023684#M683256</link>
    <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;it's time for awk, IMHO. I see no info for 'Company', so I do not anchor that string and assume the requested value is the last field (like for the other pattern).&lt;BR /&gt;&lt;BR /&gt;awk '/^Hostname:/ {hname=$NF}&lt;BR /&gt;/^Hostid:/ {hid=$NF}&lt;BR /&gt;/^Release/ {rel=$NF}&lt;BR /&gt;/Company/  {com=$NF}&lt;BR /&gt;/^Kernel architecture:/ {arch=$NF}&lt;BR /&gt;/^Kernel version:/ {ver=$3;for(i=4;i&amp;lt;=NF;i++) ver=ver" "$i }&lt;BR /&gt;/^Application architecture:/ {mach=$NF}&lt;BR /&gt;/^Date:/ {date=$NF}&lt;BR /&gt;/^Uptime:/ {upt=$2;for(i=3;i&amp;lt;=NF;i++) upt=upt" "$i }&lt;BR /&gt;END { printf("%s;%s;%s;%s;%s;%s;%s;%s;%s\n",hname,hid,rel,com,arch,ver,mach,date,upt)}' README&lt;BR /&gt;&lt;BR /&gt;I would add some error checking as well, like instead&lt;BR /&gt;&amp;gt;&amp;gt;&lt;BR /&gt;   gunzip $FILE&lt;BR /&gt;   tar xf *.tar&lt;BR /&gt;   cd explorer.*&lt;BR /&gt;&amp;lt;&amp;lt;&lt;BR /&gt;use in KSH&lt;BR /&gt;   if ! gunzip&amp;lt;$file | tar xf -&lt;BR /&gt;   then exit 1&lt;BR /&gt;   fi&lt;BR /&gt;   cd explorer.*&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 19 Jan 2007 11:46:08 GMT</pubDate>
    <dc:creator>Peter Nikitka</dc:creator>
    <dc:date>2007-01-19T11:46:08Z</dc:date>
    <item>
      <title>shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/5023680#M683252</link>
      <description>&lt;!--!*#--&gt;Hi all&lt;BR /&gt;&lt;BR /&gt;I have a tarball of files per machine for about 1500 machines. I need a script to read each tarball and extract certain info from files within the tarball. I need this info to be put in a comma separated flat file so it can be read in to Excel.&lt;BR /&gt;&lt;BR /&gt;so far I have &lt;BR /&gt;cd /export/home/Explorers&lt;BR /&gt;ls *.gz | while read FILE&lt;BR /&gt;do&lt;BR /&gt;        cd /export/home/Explorers&lt;BR /&gt;        # copy file to temp area&lt;BR /&gt;        cp $FILE ./temporary&lt;BR /&gt;        cd temporary&lt;BR /&gt;&lt;BR /&gt;        # extract the files&lt;BR /&gt;        gunzip $FILE&lt;BR /&gt;        tar xf *.tar&lt;BR /&gt;        cd explorer.*&lt;BR /&gt;        #extract the info&lt;BR /&gt;                grep Hostname README&lt;BR /&gt;                grep Hostid README&lt;BR /&gt;                grep Release README&lt;BR /&gt;                grep Company README&lt;BR /&gt;                grep Kernel README&lt;BR /&gt;                grep architecture README&lt;BR /&gt;                grep Date README&lt;BR /&gt;                grep Uptime README&lt;BR /&gt;#more info to be added&lt;BR /&gt;        #clean up - remove contents of temp before next explorer&lt;BR /&gt;        cd ..&lt;BR /&gt;        rm -r /export/home/SUN/Explorers/temporary/*&lt;BR /&gt;        &lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;The grep statements bring out the lines I require, but for each grep I need the data after the colon to be added to a csv file, and a new line to be started for each separate tar ball.&lt;BR /&gt;&lt;BR /&gt;example output of the greps:&lt;BR /&gt; Hostname: ipcsoiwa&lt;BR /&gt;Hostid: 8075ac8c&lt;BR /&gt;Release: 5.6&lt;BR /&gt;Kernel architecture: sun4d&lt;BR /&gt;Kernel version: SunOS 5.6 Generic 105181-06&lt;BR /&gt;Kernel architecture: sun4d&lt;BR /&gt;Application architecture: sparc&lt;BR /&gt;Date: 2005.05.30.04.54&lt;BR /&gt;Uptime:   6:02am  up 43 min(s),  2 users,  load average: 1.34, 1.16, 0.66&lt;BR /&gt;&lt;BR /&gt;Thanks &lt;BR /&gt;&lt;BR /&gt;Mark</description>
      <pubDate>Fri, 19 Jan 2007 09:41:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/5023680#M683252</guid>
      <dc:creator>Mark McDonald_2</dc:creator>
      <dc:date>2007-01-19T09:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/5023681#M683253</link>
      <description>Well, this is probably ugly, but it should work:&lt;BR /&gt;&lt;BR /&gt;HOST=$(grep Hostname README | awk -F : '{ print $2}')&lt;BR /&gt;HOSTID=$(grep Hostid README | awk -F : '{ print $2}')&lt;BR /&gt;RELEASE=$(grep Release README | awk -F : '{ print $2}')&lt;BR /&gt;COMPANY=$(grep Company README | awk -F : '{ print $2}')&lt;BR /&gt;KERNEL=$(grep Kernel README | awk -F : '{ print $2}')&lt;BR /&gt;ARCH=$(grep architecture README | awk -F : '{ print $2}')&lt;BR /&gt;DATE=$(grep Date README | awk -F : '{ print $2}')&lt;BR /&gt;UPTIME=$(grep Uptime README | awk -F : '{ print $2}')&lt;BR /&gt;&lt;BR /&gt;echo "${HOSTNAME},${HOSTID},${RELEASE},${KERNEL},${ARCH},${DATE},${UPTIME}" &amp;gt;&amp;gt; /dir/afile&lt;BR /&gt;&lt;BR /&gt;Another slight improvement is you can combine your gunzip and tar commands into a single line.&lt;BR /&gt;&lt;BR /&gt;Instead of: &lt;BR /&gt;&lt;BR /&gt;gunzip $FILE&lt;BR /&gt;tar xf *.tar&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;gzcat $FILE | tar xf -&lt;BR /&gt;&lt;BR /&gt;(Note there is a space between the 'xf' and the '-')</description>
      <pubDate>Fri, 19 Jan 2007 09:57:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/5023681#M683253</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2007-01-19T09:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/5023682#M683254</link>
      <description>I just noticed one thing that could lead to some difficulty.&lt;BR /&gt;&lt;BR /&gt;You have this grep statement:&lt;BR /&gt;&lt;BR /&gt;grep Kernel README&lt;BR /&gt;&lt;BR /&gt;which will return 2 lines of data:&lt;BR /&gt;&lt;BR /&gt;Kernel architecture: sun4d&lt;BR /&gt;Kernel version: SunOS 5.6 Generic 105181-06&lt;BR /&gt;&lt;BR /&gt;Then you also grep for architecture.  Which will return the Kernel architecture line again.  For those you should probably do this:&lt;BR /&gt;&lt;BR /&gt; KERNEL=$(grep "Kernel version" README | awk -F : '{ print $2}')&lt;BR /&gt;ARCH=$(grep "Kernel architecture" README | awk -F : '{ print $2}') &lt;BR /&gt;&lt;BR /&gt;This way you should only get one line per grep.</description>
      <pubDate>Fri, 19 Jan 2007 10:01:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/5023682#M683254</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2007-01-19T10:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/5023683#M683255</link>
      <description>Thanks&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 19 Jan 2007 10:15:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/5023683#M683255</guid>
      <dc:creator>Mark McDonald_2</dc:creator>
      <dc:date>2007-01-19T10:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/5023684#M683256</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;it's time for awk, IMHO. I see no info for 'Company', so I do not anchor that string and assume the requested value is the last field (like for the other pattern).&lt;BR /&gt;&lt;BR /&gt;awk '/^Hostname:/ {hname=$NF}&lt;BR /&gt;/^Hostid:/ {hid=$NF}&lt;BR /&gt;/^Release/ {rel=$NF}&lt;BR /&gt;/Company/  {com=$NF}&lt;BR /&gt;/^Kernel architecture:/ {arch=$NF}&lt;BR /&gt;/^Kernel version:/ {ver=$3;for(i=4;i&amp;lt;=NF;i++) ver=ver" "$i }&lt;BR /&gt;/^Application architecture:/ {mach=$NF}&lt;BR /&gt;/^Date:/ {date=$NF}&lt;BR /&gt;/^Uptime:/ {upt=$2;for(i=3;i&amp;lt;=NF;i++) upt=upt" "$i }&lt;BR /&gt;END { printf("%s;%s;%s;%s;%s;%s;%s;%s;%s\n",hname,hid,rel,com,arch,ver,mach,date,upt)}' README&lt;BR /&gt;&lt;BR /&gt;I would add some error checking as well, like instead&lt;BR /&gt;&amp;gt;&amp;gt;&lt;BR /&gt;   gunzip $FILE&lt;BR /&gt;   tar xf *.tar&lt;BR /&gt;   cd explorer.*&lt;BR /&gt;&amp;lt;&amp;lt;&lt;BR /&gt;use in KSH&lt;BR /&gt;   if ! gunzip&amp;lt;$file | tar xf -&lt;BR /&gt;   then exit 1&lt;BR /&gt;   fi&lt;BR /&gt;   cd explorer.*&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 19 Jan 2007 11:46:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/5023684#M683256</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2007-01-19T11:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/5023685#M683257</link>
      <description>.</description>
      <pubDate>Thu, 11 Dec 2008 00:17:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script/m-p/5023685#M683257</guid>
      <dc:creator>Mark McDonald_2</dc:creator>
      <dc:date>2008-12-11T00:17:10Z</dc:date>
    </item>
  </channel>
</rss>

