<?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: Bash Conditionals in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/bash-conditionals/m-p/4473817#M37797</link>
    <description>Here is a ksh example where I go crazy with (( )):&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1358125" target="_blank"&gt;http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1358125&lt;/A&gt;</description>
    <pubDate>Fri, 07 Aug 2009 23:13:11 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2009-08-07T23:13:11Z</dc:date>
    <item>
      <title>Bash Conditionals</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-conditionals/m-p/4473812#M37792</link>
      <description>Hi Folks&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I am having a problem with a script that checks for ntp drift and timezone, the ntp drift part is fine.&lt;BR /&gt;&lt;BR /&gt;What I want is the script to check for both conditions and display the results accordingly&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;# time-offset_check.sh&lt;BR /&gt;#&lt;BR /&gt;# Checks computer clock against specified NTP server. Issues a warning&lt;BR /&gt;# on stdout, if the time difference exceeds limit.  Requires ntpdate, bc&lt;BR /&gt;# and egrep in path. Run from cron as often as you like.&lt;BR /&gt;&lt;BR /&gt;### Options&lt;BR /&gt;&lt;BR /&gt;TIMEZONE=`date | awk '{ print$5}'`&lt;BR /&gt;NTPSERVER='10.17.0.80'   # i.e. random server from pool.ntp.org&lt;BR /&gt;LIMIT='150.000000'           # i.e. 1.000000 (= 1 second)&lt;BR /&gt;LOCALTIMEZONE='GMT'&lt;BR /&gt;### Do not edit&lt;BR /&gt;&lt;BR /&gt;OFFSET=`/usr/sbin/ntpdate -q $NTPSERVER \&lt;BR /&gt;        | egrep -o -m 1 -e "offset ((-)?[0-9]+\.[0-9]+)" \&lt;BR /&gt;        | egrep -o -e "[0-9]+\.[0-9]+"`&lt;BR /&gt;&lt;BR /&gt;RESULT=`echo "$OFFSET &amp;gt;= $LIMIT" | bc`&lt;BR /&gt;&lt;BR /&gt;if (("$RESULT" == 1)); then&lt;BR /&gt;        echo "Warning: Local clock offset ($OFFSET) larger than limit ($LIMIT) - Check NTPD"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if  (("$TIMEZONE" !="GMT")); then&lt;BR /&gt;        echo "Warning: Local Time Zone is not set to GMT - Check /etc/sysconfig/clock or /etc/localtime"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;exit 0&lt;BR /&gt;~                                                                                                                                                                                                                   &lt;BR /&gt;When I set the timezone to MET I get&lt;BR /&gt;&lt;BR /&gt;[root@sburt-lap seb]# ./time-offset_check.sh&lt;BR /&gt;++ date&lt;BR /&gt;++ awk '{ print$5}'&lt;BR /&gt;+ TIMEZONE=MET&lt;BR /&gt;+ NTPSERVER=10.17.0.80&lt;BR /&gt;+ LIMIT=150.000000&lt;BR /&gt;+ LOCALTIMEZONE=GMT&lt;BR /&gt;++ /usr/sbin/ntpdate -q 10.17.0.80&lt;BR /&gt;++ egrep -o -m 1 -e 'offset ((-)?[0-9]+\.[0-9]+)'&lt;BR /&gt;++ egrep -o -e '[0-9]+\.[0-9]+'&lt;BR /&gt;+ OFFSET=18631470.639141&lt;BR /&gt;++ echo '18631470.639141 &amp;gt;= 150.000000'&lt;BR /&gt;++ bc&lt;BR /&gt;+ RESULT=1&lt;BR /&gt;+ (( 1 == 1 ))&lt;BR /&gt;+ echo 'Warning: Local clock offset (18631470.639141) larger than limit (150.000000) - Check NTPD'&lt;BR /&gt;Warning: Local clock offset (18631470.639141) larger than limit (150.000000) - Check NTPD&lt;BR /&gt;+ (( MET != GMT ))&lt;BR /&gt;+ exit 0&lt;BR /&gt;[root@sburt-lap seb]# &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I am not sure where I am going wrong...&lt;BR /&gt;&lt;BR /&gt;Thanking you...&lt;BR /&gt;&lt;BR /&gt;--Steve</description>
      <pubDate>Wed, 05 Aug 2009 12:06:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-conditionals/m-p/4473812#M37792</guid>
      <dc:creator>Steve Burt_1</dc:creator>
      <dc:date>2009-08-05T12:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Bash Conditionals</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-conditionals/m-p/4473813#M37793</link>
      <description>if [ condition ]&lt;BR /&gt;then&lt;BR /&gt;action&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This works:&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;# time-offset_check.sh&lt;BR /&gt;#&lt;BR /&gt;# Checks computer clock against specified NTP server. Issues a warning&lt;BR /&gt;# on stdout, if the time difference exceeds limit. Requires ntpdate, bc&lt;BR /&gt;# and egrep in path. Run from cron as often as you like.&lt;BR /&gt;&lt;BR /&gt;### Options&lt;BR /&gt;&lt;BR /&gt;TIMEZONE=`date | awk '{ print$5}'`&lt;BR /&gt;NTPSERVER='10.129.4.123' # i.e. random server from pool.ntp.org&lt;BR /&gt;LIMIT='150.000000' # i.e. 1.000000 (= 1 second)&lt;BR /&gt;LOCALTIMEZONE='GMT'&lt;BR /&gt;### Do not edit&lt;BR /&gt;&lt;BR /&gt;OFFSET=`/usr/sbin/ntpdate -q $NTPSERVER \&lt;BR /&gt;| egrep -o -m 1 -e "offset ((-)?[0-9]+\.[0-9]+)" \&lt;BR /&gt;| egrep -o -e "[0-9]+\.[0-9]+"`&lt;BR /&gt;&lt;BR /&gt;RESULT=`echo "$OFFSET &amp;gt;= $LIMIT" | bc`&lt;BR /&gt;&lt;BR /&gt;if [ "$RESULT" == 1 ]&lt;BR /&gt;then&lt;BR /&gt;echo "Warning: Local clock offset ($OFFSET) larger than limit ($LIMIT) - Check NTPD"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if [ "$TIMEZONE" != "GMT" ]&lt;BR /&gt;then&lt;BR /&gt;echo "Warning: Local Time Zone is not set to GMT - Check /etc/sysconfig/clock or /etc/localtime"&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Aug 2009 12:42:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-conditionals/m-p/4473813#M37793</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2009-08-05T12:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Bash Conditionals</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-conditionals/m-p/4473814#M37794</link>
      <description>The "(( expression ))" syntax is for arithmetic expressions only. It is regarded as "false" if and only if the arithmetic expression inside evaluates to 0. &lt;BR /&gt;&lt;BR /&gt;(( 1 == 1 )) evaluates to 1 just like in C, so the expression is "true" and you get your warning.&lt;BR /&gt;&lt;BR /&gt;(( MET != GMT )) is non-arithmetic, so it evaluates to 0 and the expression is false.&lt;BR /&gt;&lt;BR /&gt;For conditional expressions, you'll want "[ expression ]" (as Ivan already posted) or "[[ expression ]]".&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Wed, 05 Aug 2009 12:55:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-conditionals/m-p/4473814#M37794</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2009-08-05T12:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: Bash Conditionals</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-conditionals/m-p/4473815#M37795</link>
      <description>Ivan,&lt;BR /&gt;&lt;BR /&gt;Many thanks for your helpful explaination...&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Wed, 05 Aug 2009 14:36:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-conditionals/m-p/4473815#M37795</guid>
      <dc:creator>Steve Burt_1</dc:creator>
      <dc:date>2009-08-05T14:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: Bash Conditionals</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-conditionals/m-p/4473816#M37796</link>
      <description>I should say Matt as well... Thanking you both its very much apreciated&lt;BR /&gt;&lt;BR /&gt;--Steve</description>
      <pubDate>Thu, 06 Aug 2009 06:39:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-conditionals/m-p/4473816#M37796</guid>
      <dc:creator>Steve Burt_1</dc:creator>
      <dc:date>2009-08-06T06:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Bash Conditionals</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-conditionals/m-p/4473817#M37797</link>
      <description>Here is a ksh example where I go crazy with (( )):&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1358125" target="_blank"&gt;http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1358125&lt;/A&gt;</description>
      <pubDate>Fri, 07 Aug 2009 23:13:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-conditionals/m-p/4473817#M37797</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-08-07T23:13:11Z</dc:date>
    </item>
  </channel>
</rss>

