<?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: script execution fails when executed from crontab in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/script-execution-fails-when-executed-from-crontab/m-p/5219056#M51613</link>
    <description>&amp;gt;MK: cur=$(awk '{print $1}' &amp;lt; /proc/loadavg | tr -d, | cut -d. -f1)&lt;BR /&gt;&lt;BR /&gt;Besides this change, you can probably replace tr(1) and cut(1) by more awk functions.</description>
    <pubDate>Sat, 16 Jan 2010 08:09:32 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2010-01-16T08:09:32Z</dc:date>
    <item>
      <title>script execution fails when executed from crontab</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-execution-fails-when-executed-from-crontab/m-p/5219052#M51609</link>
      <description>&lt;!--!*#--&gt;I have scheduled a script to run in crontab. the script monitors the load average and sends an email if load avg is above certain limit.&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;avg=`uptime | awk '{print $8" " $9 " "$10 $11 $12 }' | tr -s , " "`&lt;BR /&gt;cur=`more /proc/loadavg | awk '{print $1}' | tr -d , | cut -d. -f1`&lt;BR /&gt;str="============================="&lt;BR /&gt;info="Curent $avg"&lt;BR /&gt;&lt;BR /&gt;if [ $cur -ge 6 ]; then&lt;BR /&gt;info1="Server load is high presently"&lt;BR /&gt;touch /tmp/tmp.00&lt;BR /&gt;echo -e "$str\n$info\n$info1\n$str\n" &amp;gt;&amp;gt; /tmp/tmp.00&lt;BR /&gt;ps aux | head -1 &amp;gt;&amp;gt; /tmp/tmp.00&lt;BR /&gt;ps aux | sort -rn +2 | head -10 &amp;gt;&amp;gt; /tmp/tmp.00;&lt;BR /&gt;mail -s "Alert: Load Average for `hostname` on `date` " email1 &amp;lt; /tmp/tmp.00;&lt;BR /&gt;mail -s "Alert: Load Average for `hostname` on `date` " email2 &amp;lt; /tmp/tmp.00;&lt;BR /&gt;rm -f /tmp/tmp.00&lt;BR /&gt;else&lt;BR /&gt;#echo -e "$str\n$info\n$str"&lt;BR /&gt;exit 0;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;when i execute this script i don get any error.&lt;BR /&gt;However, when it runs through cron it throws an error.&lt;BR /&gt;&lt;BR /&gt;./monitor_loadavg.sh: line 7: [: too many arguments&lt;BR /&gt;&lt;BR /&gt;i don see anything wrong with line 7.&lt;BR /&gt;&lt;BR /&gt;Please suggest if i am doing anything wrong&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;SUnny</description>
      <pubDate>Wed, 13 Jan 2010 16:52:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-execution-fails-when-executed-from-crontab/m-p/5219052#M51609</guid>
      <dc:creator>Sunny Jaisinghani</dc:creator>
      <dc:date>2010-01-13T16:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: script execution fails when executed from crontab</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-execution-fails-when-executed-from-crontab/m-p/5219053#M51610</link>
      <description>The problem is probably in the content of the $cur variable somehow.&lt;BR /&gt;&lt;BR /&gt;On line 3, you use the "more" command to read /proc/loadavg. When you're running the script in your session, "more" can find the $TERM and $LINES environment variables that identify your terminal type and the number of lines in your terminal window.&lt;BR /&gt;&lt;BR /&gt;But when running from cron, there is no terminal, and those variables won't exist. I guess "more" might produce some extra output (a notification message or something). You don't need it anyway: this version of line 3 of your script should work just the same, but without the uncertain behavior of "more":&lt;BR /&gt;&lt;BR /&gt;cur=$(awk '{print $1}' &amp;lt; /proc/loadavg | tr -d, | cut -d. -f1)&lt;BR /&gt;&lt;BR /&gt;mK</description>
      <pubDate>Wed, 13 Jan 2010 17:26:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-execution-fails-when-executed-from-crontab/m-p/5219053#M51610</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2010-01-13T17:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: script execution fails when executed from crontab</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-execution-fails-when-executed-from-crontab/m-p/5219054#M51611</link>
      <description>&lt;!--!*#--&gt;&amp;gt; i don see anything wrong with line 7.&lt;BR /&gt;&lt;BR /&gt;Probably because you don't see what "$cur"&lt;BR /&gt;is.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; if [ $cur -ge 6 ]; then&lt;BR /&gt;&lt;BR /&gt;      if [ "$cur" -ge 6 ]; then&lt;BR /&gt;&lt;BR /&gt;But, if "cur" contains multiple tokens, then&lt;BR /&gt;you'll probably need to look more closely at&lt;BR /&gt;its definition.</description>
      <pubDate>Wed, 13 Jan 2010 17:28:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-execution-fails-when-executed-from-crontab/m-p/5219054#M51611</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-01-13T17:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: script execution fails when executed from crontab</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-execution-fails-when-executed-from-crontab/m-p/5219055#M51612</link>
      <description>Probably some of the commands for filling the cur variable is not working. This produces the error in line 7 as cur is empty or missformatted. Try adding the fill path to the more, awk, cut y tr commands.&lt;BR /&gt;&lt;BR /&gt;Add an echo $cur on line 6 to debug the problem.</description>
      <pubDate>Wed, 13 Jan 2010 18:24:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-execution-fails-when-executed-from-crontab/m-p/5219055#M51612</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2010-01-13T18:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: script execution fails when executed from crontab</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-execution-fails-when-executed-from-crontab/m-p/5219056#M51613</link>
      <description>&amp;gt;MK: cur=$(awk '{print $1}' &amp;lt; /proc/loadavg | tr -d, | cut -d. -f1)&lt;BR /&gt;&lt;BR /&gt;Besides this change, you can probably replace tr(1) and cut(1) by more awk functions.</description>
      <pubDate>Sat, 16 Jan 2010 08:09:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-execution-fails-when-executed-from-crontab/m-p/5219056#M51613</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-01-16T08:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: script execution fails when executed from crontab</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-execution-fails-when-executed-from-crontab/m-p/5219057#M51614</link>
      <description>Thanks Matti,&lt;BR /&gt;&lt;BR /&gt;your suggestion worked for me.</description>
      <pubDate>Sat, 16 Jan 2010 17:25:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-execution-fails-when-executed-from-crontab/m-p/5219057#M51614</guid>
      <dc:creator>Sunny Jaisinghani</dc:creator>
      <dc:date>2010-01-16T17:25:01Z</dc:date>
    </item>
  </channel>
</rss>

