<?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: echo to a file in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870891#M98774</link>
    <description>You can zero out the logfile when the script starts so that entries from the last run do not fill it up in case there are no critical or warning alerts...&lt;BR /&gt;&lt;BR /&gt;cat /dev/null &amp;gt; $LOG&lt;BR /&gt;&lt;BR /&gt;and remove the following command from your script...&lt;BR /&gt;&lt;BR /&gt;echo "End Of File" &amp;gt;&amp;gt; $LOG</description>
    <pubDate>Wed, 27 Sep 2006 11:11:06 GMT</pubDate>
    <dc:creator>Sandman!</dc:creator>
    <dc:date>2006-09-27T11:11:06Z</dc:date>
    <item>
      <title>echo to a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870889#M98772</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I am writing a script to check the filesystems then write the output to a logfile if they have gone over a certain threshold:&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;&lt;BR /&gt;DIR=/sysadmin/scripts/admin&lt;BR /&gt;LOG=$DIR/msgfile.out&lt;BR /&gt;&lt;BR /&gt;WARN=50&lt;BR /&gt;CRIT=80&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;                for a in COMMAND=`df | tail +2 | awk '{print $7,$4}' | sed s/%//g | sed s/' '/:/g |grep -v /proc`&lt;BR /&gt;                do&lt;BR /&gt;&lt;BR /&gt;                FILESYS=`echo $COMMAND | cut -d":" -f1`&lt;BR /&gt;                USED=`echo $COMMAND | cut -d":" -f2`&lt;BR /&gt;&lt;BR /&gt;                        if [ $USED -gt $WARN ] ; then&lt;BR /&gt;                        echo " ######### WARNING ########### " &amp;gt; $LOGFILE&lt;BR /&gt;                        echo " $FILESYS filesystem is at $USED " &amp;gt;&amp;gt; $LOG&lt;BR /&gt;                        fi&lt;BR /&gt;                done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;                for a in COMMAND=`df | tail +2 | awk '{print $7,$4}' | sed s/%//g | sed s/' '/:/g |grep -v /proc`&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;                FILESYS=`echo $COMMAND | cut -d":" -f1`&lt;BR /&gt;                USED=`echo $COMMAND | cut -d":" -f2`&lt;BR /&gt;&lt;BR /&gt;                                if [ $USED -gt $CRIT ] ; then&lt;BR /&gt;                                echo "\n ######### CRITICAL ########### " &amp;gt;&amp;gt; $LOG&lt;BR /&gt;                                echo " $FILESYS filesystem is at $USED " &amp;gt;&amp;gt; $LOG&lt;BR /&gt;                                fi&lt;BR /&gt;                done&lt;BR /&gt;                                echo "End Of File" &amp;gt;&amp;gt; $LOG&lt;BR /&gt;&lt;BR /&gt;The issue I have is formatting the logfile - I would like the output like so:&lt;BR /&gt;&lt;BR /&gt;####### WARNING ###########&lt;BR /&gt;&lt;BR /&gt;/  filesystem is at 68%&lt;BR /&gt;/home filesystem is at 55%&lt;BR /&gt;etc&lt;BR /&gt;&lt;BR /&gt;####### CRITICAL ###########&lt;BR /&gt;&lt;BR /&gt;/var filesystem is at 94%&lt;BR /&gt;/tmp filesystem is at 88%&lt;BR /&gt;&lt;BR /&gt;etc&lt;BR /&gt;&lt;BR /&gt;End of File&lt;BR /&gt;&lt;BR /&gt;however I do not want any output to the file if there is no critical or warning alerts.&lt;BR /&gt;&lt;BR /&gt;any idea's??&lt;BR /&gt;&lt;BR /&gt;Thanks a million&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Wed, 27 Sep 2006 10:56:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870889#M98772</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2006-09-27T10:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: echo to a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870890#M98773</link>
      <description>Chris,&lt;BR /&gt;you describe what the output SHOULD look like, but not how it currently look like.&lt;BR /&gt;Can you please give an example of a non-acceptable output file.</description>
      <pubDate>Wed, 27 Sep 2006 11:04:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870890#M98773</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-09-27T11:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: echo to a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870891#M98774</link>
      <description>You can zero out the logfile when the script starts so that entries from the last run do not fill it up in case there are no critical or warning alerts...&lt;BR /&gt;&lt;BR /&gt;cat /dev/null &amp;gt; $LOG&lt;BR /&gt;&lt;BR /&gt;and remove the following command from your script...&lt;BR /&gt;&lt;BR /&gt;echo "End Of File" &amp;gt;&amp;gt; $LOG</description>
      <pubDate>Wed, 27 Sep 2006 11:11:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870891#M98774</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-09-27T11:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: echo to a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870892#M98775</link>
      <description>Hi Chris:&lt;BR /&gt;&lt;BR /&gt;If a well-formatted output is your goal, consider replacing simple 'echo' statements for formatted 'printf' ones.  For example:&lt;BR /&gt;&lt;BR /&gt;# printf "filesystem %s is at %d%%\n" "/var" 50&lt;BR /&gt;&lt;BR /&gt;...note the double "%" character to yield:&lt;BR /&gt;&lt;BR /&gt;filesystem /var is at 50%&lt;BR /&gt;&lt;BR /&gt;See the manpages for 'printf(1)' for more information.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 27 Sep 2006 11:15:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870892#M98775</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-09-27T11:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: echo to a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870893#M98776</link>
      <description>Your fundamental problem is that &lt;BR /&gt;echo "End of File" &amp;gt;&amp;gt; ${LOG} is done unconditionally so you simply need to add a bit of logic.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset -i ECHOED=0 # flag, initialize to 0&lt;BR /&gt;&lt;BR /&gt;for a in COMMAND=`df | tail +2 | awk '{print $7,$4}' | sed s/%//g | sed s/' '/:/g |grep -v /proc`&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;FILESYS=`echo $COMMAND | cut -d":" -f1`&lt;BR /&gt;USED=`echo $COMMAND | cut -d":" -f2`&lt;BR /&gt;&lt;BR /&gt;if [ $USED -gt $WARN ] ; then&lt;BR /&gt;echo " ######### WARNING ########### " &amp;gt; $LOGFILE&lt;BR /&gt;echo " $FILESYS filesystem is at $USED " &amp;gt;&amp;gt; $LOG&lt;BR /&gt;ECHOED=1 #set flag to 1&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;for a in COMMAND=`df | tail +2 | awk '{print $7,$4}' | sed s/%//g | sed s/' '/:/g |grep -v /proc`&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;FILESYS=`echo $COMMAND | cut -d":" -f1`&lt;BR /&gt;USED=`echo $COMMAND | cut -d":" -f2`&lt;BR /&gt;&lt;BR /&gt;if [ $USED -gt $CRIT ] ; then&lt;BR /&gt;echo "\n ######### CRITICAL ########### " &amp;gt;&amp;gt; $LOG&lt;BR /&gt;echo " $FILESYS filesystem is at $USED " &amp;gt;&amp;gt; $LOG&lt;BR /&gt;ECHOED=1 #set flag to 1&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;# if flag != 0 then echo&lt;BR /&gt;if [[ ${ECHOED} -ne 0 ]]&lt;BR /&gt;  then&lt;BR /&gt;echo "End Of File" &amp;gt;&amp;gt; $LOG&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 27 Sep 2006 11:16:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870893#M98776</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-09-27T11:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: echo to a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870894#M98777</link>
      <description>From a quick glance at the script, present output:&lt;BR /&gt;* has the "WARNING" and "CRITICAL" headings appear once for each match,&lt;BR /&gt;* has messages that are not sorted by disk utilization.&lt;BR /&gt;&lt;BR /&gt;I will rewrite the script for you after I get back from Wal-mart, unless someone else does it first.&lt;BR /&gt;&lt;BR /&gt;One thing to point out--I notice you have:&lt;BR /&gt;echo " ######### WARNING ########### " &amp;gt; $LOGFILE&lt;BR /&gt;&lt;BR /&gt;instead of:&lt;BR /&gt;&lt;BR /&gt;echo " ######### WARNING ########### " &amp;gt; $LOG&lt;BR /&gt;&lt;BR /&gt;PCS</description>
      <pubDate>Wed, 27 Sep 2006 11:17:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870894#M98777</guid>
      <dc:creator>spex</dc:creator>
      <dc:date>2006-09-27T11:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: echo to a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870895#M98778</link>
      <description>Chris,&lt;BR /&gt;also are you sure about your df command, as I can't line up your output with the output of df. I get something like:&lt;BR /&gt;/home                (/dev/vg00/lvol5     ):   400112 blocks      6294 i-nodes&lt;BR /&gt;&lt;BR /&gt;Are you running this on HPUX or another platform?</description>
      <pubDate>Wed, 27 Sep 2006 11:21:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870895#M98778</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-09-27T11:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: echo to a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870896#M98779</link>
      <description>Hi Chris:&lt;BR /&gt;&lt;BR /&gt;I agree with Peter, I suspect that you're running on a Linux or AIX platform from the exclusion of the '/proc' filesystem.  No matter for the purposes here, however.&lt;BR /&gt;&lt;BR /&gt;You can greatly reduce the number of separate processes that run to collect your data.  For your principal COMMAND, you could do:&lt;BR /&gt;&lt;BR /&gt;# COMMAND=`df|awk 'NR&amp;gt;1 &amp;amp;&amp;amp; !/\/proc$/ {print $7,$4}'|sed -e s/%//g -e s/' '/:/g`  &lt;BR /&gt;&lt;BR /&gt;This eliminates a 'tail' process, a 'grep' and reduces two 'sed' processes to one.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 27 Sep 2006 11:36:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870896#M98779</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-09-27T11:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: echo to a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870897#M98780</link>
      <description>the output in the msgfile.out should look like &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;####### WARNING ############&lt;BR /&gt;&lt;BR /&gt;/ is at 55%&lt;BR /&gt;/usr is at 60%&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;####### CRITICAL #########&lt;BR /&gt;&lt;BR /&gt;/tmp is at 90%&lt;BR /&gt;/home is at 95%&lt;BR /&gt;&lt;BR /&gt;End of File&lt;BR /&gt;&lt;BR /&gt;Thanks for the suggestions so far</description>
      <pubDate>Mon, 02 Oct 2006 07:32:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870897#M98780</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2006-10-02T07:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: echo to a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870898#M98781</link>
      <description>df on my HP server does not produce the same output as youlisted. I use bdf:&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;&lt;BR /&gt;DIR=/sysadmin/scripts/admin&lt;BR /&gt;LOG=$DIR/msgfile.out&lt;BR /&gt;&lt;BR /&gt;echo "####### WARNING ###########" &amp;gt; $LOG&lt;BR /&gt;&lt;BR /&gt;bdf | grep -v "\/proc" | awk ' {print $5 " " $6} ' | sed 's/\%//'|awk '&lt;BR /&gt;   {&lt;BR /&gt;     if ( $1 &amp;gt; 50 )&lt;BR /&gt;        if ( $1 &amp;lt; 80 )&lt;BR /&gt;     print $2 " is at " $1 "%"&lt;BR /&gt;} ' &amp;gt;&amp;gt; $LOG&lt;BR /&gt;&lt;BR /&gt;echo "####### CRITICAL ###########" &amp;gt;&amp;gt; $LOG&lt;BR /&gt;&lt;BR /&gt;bdf | grep -v "\/proc" | awk ' {print $5 " " $6} ' | sed 's/\%//'|awk '&lt;BR /&gt;   {&lt;BR /&gt;     if ( $1 &amp;gt; 80 )&lt;BR /&gt;     print $2 " is at " $1 "%"&lt;BR /&gt;} ' &amp;gt;&amp;gt; $LOG&lt;BR /&gt;&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Yang</description>
      <pubDate>Mon, 02 Oct 2006 08:25:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/echo-to-a-file/m-p/3870898#M98781</guid>
      <dc:creator>Yang Qin_1</dc:creator>
      <dc:date>2006-10-02T08:25:52Z</dc:date>
    </item>
  </channel>
</rss>

