<?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 to calculate the total idle minutes in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029568#M97785</link>
    <description>&amp;gt;Oscar: According to sh-posix man pages: If UNIX95 is defined, &lt;BR /&gt;&lt;BR /&gt;On 11.23, this UNIX95 has been removed.  In all cases it: &lt;BR /&gt;... will be processed according to ISOC standard</description>
    <pubDate>Wed, 21 Feb 2007 14:40:41 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2007-02-21T14:40:41Z</dc:date>
    <item>
      <title>Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029554#M97771</link>
      <description>I have a small script that reads in an output with format as follows:&lt;BR /&gt;&lt;BR /&gt;ivcheung pts/th .&lt;BR /&gt;ivcheung pts/tp .&lt;BR /&gt;ktam pts/tx 0:02&lt;BR /&gt;kwchow pts/tr 0:54&lt;BR /&gt;mmak pts/tk 1:16&lt;BR /&gt;ritali pts/tc 0:01&lt;BR /&gt;rwong pts/tt 0:08&lt;BR /&gt;tchan pts/tw 0:15&lt;BR /&gt;&lt;BR /&gt;Then find out those telnet sessions that have been idled for more than 30 minutes&lt;BR /&gt;&lt;BR /&gt;My script is like :&lt;BR /&gt;&lt;BR /&gt;num=`grep pts $tempdir/whodo.out | wc | cut -f1 -d' '`&lt;BR /&gt;lines=1&lt;BR /&gt;while (( num &amp;gt; 0 ))&lt;BR /&gt;do &lt;BR /&gt;   info=`head -n $lines $tempdir/whodo.out | tail -1`&lt;BR /&gt;   userid=`echo $info | cut -f1 -d' '`&lt;BR /&gt;   tty=`echo $info | cut -f2 -d' '`&lt;BR /&gt;   idle=`echo $info | cut -f3 -d' '`&lt;BR /&gt;   if [ $idle = "old" ]&lt;BR /&gt;   then&lt;BR /&gt;      idle_min=999999&lt;BR /&gt;   else&lt;BR /&gt;     (( idle_min = $(echo $idle|cut -f1 -d':') * 60 + $(echo $idle|cut -f2 -d':'&lt;BR /&gt;) ))&lt;BR /&gt;   fi&lt;BR /&gt;   if [ $idle_min -gt 30 ]&lt;BR /&gt;   then&lt;BR /&gt;      tty="/dev/"$tty&lt;BR /&gt;      ( invoke another script to kill the idled session )&lt;BR /&gt;   fi&lt;BR /&gt;   (( lines = lines + 1 )) &lt;BR /&gt;   (( num = num - 1 ))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This script used to work fine until recently I moved from a 11.0 server to another 11.i server, if the idled time = "0:08" or "0:09", error message would occur&lt;BR /&gt;&lt;BR /&gt;08 : The specified number is not valid for this command.&lt;BR /&gt;&lt;BR /&gt;I know I can use&lt;BR /&gt;&lt;BR /&gt;echo $(( 10#08 )) &lt;BR /&gt;&lt;BR /&gt;to force a base 10 echo but don't know how to embed this into the old lines&lt;BR /&gt;&lt;BR /&gt;Rita</description>
      <pubDate>Wed, 21 Feb 2007 02:02:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029554#M97771</guid>
      <dc:creator>Rita Li</dc:creator>
      <dc:date>2007-02-21T02:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029555#M97772</link>
      <description>&lt;!--!*#--&gt;There have been other posts on this issue of leading zeros.  You may want to use:&lt;BR /&gt;   typeset -LZ idle=$(echo $info | cut -f3 -d' ')&lt;BR /&gt;&lt;BR /&gt;&amp;gt;num=`grep pts $tempdir/whodo.out | wc | cut -f1 -d' '`&lt;BR /&gt;&lt;BR /&gt;Why do you need the cut?  wc -l will give lines directly.  Also, you can use grep -c, so you don't need wc.&lt;BR /&gt;&lt;BR /&gt;Any reason you use num and a while loop and  getting the lines one at a time with: info=`head -n $lines $tempdir/whodo.out | tail -1`&lt;BR /&gt;Why not use awk to process the whole file until EOF?&lt;BR /&gt;&lt;BR /&gt;By using awk, you can make it lots simpler to read.  And no stinkin' problems with garbage "octal" leading zeroes.  And you don't need to use cut.  You would have to use substr for the ":" extraction of the MM:SS time.&lt;BR /&gt;&lt;BR /&gt;If you aren't familiar with awk, you could at least use:&lt;BR /&gt;   grep pts $tempdir/whodo.out |&lt;BR /&gt;    while read userid tty idle; do&lt;BR /&gt;   ...&lt;BR /&gt;   done</description>
      <pubDate>Wed, 21 Feb 2007 02:32:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029555#M97772</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-02-21T02:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029556#M97773</link>
      <description>My problem is: I am not familar with awk</description>
      <pubDate>Wed, 21 Feb 2007 03:21:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029556#M97773</guid>
      <dc:creator>Rita Li</dc:creator>
      <dc:date>2007-02-21T03:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029557#M97774</link>
      <description>Rita,&lt;BR /&gt;you could try:&lt;BR /&gt;idle_hr=`echo ${idle} |cut -f1 -d':'`&lt;BR /&gt;idle_min=`echo ${idle} |cut -f2 -d':'`&lt;BR /&gt;idle_total=`echo "$idle_hr * 60 + $idle_min"|bc`&lt;BR /&gt;&lt;BR /&gt;instead of your:&lt;BR /&gt;(( idle_min = $(echo $idle|cut -f1 -d':') * 60 + $(echo $idle|cut -f2 -d':'&lt;BR /&gt;) ))&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Feb 2007 03:58:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029557#M97774</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2007-02-21T03:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029558#M97775</link>
      <description>You need to use typeset of the one with leading zeroes:&lt;BR /&gt;  typeset -LZ idle_min=$(echo $info | cut -f3 -d' ')&lt;BR /&gt;&lt;BR /&gt;&amp;gt;My problem is: I am not familar with awk&lt;BR /&gt;&lt;BR /&gt;Then use my "grep | while read userid tty idle; do" suggestion.</description>
      <pubDate>Wed, 21 Feb 2007 04:18:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029558#M97775</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-02-21T04:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029559#M97776</link>
      <description>&lt;!--!*#--&gt;&amp;gt;typeset -LZ idle_min=$(echo $info | cut -f3 -d' ')&lt;BR /&gt;&lt;BR /&gt;Oops that's not your initial value.  Just add this before your code:&lt;BR /&gt;   typeset -LZ idle_min</description>
      <pubDate>Wed, 21 Feb 2007 04:20:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029559#M97776</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-02-21T04:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029560#M97777</link>
      <description>Hi Rita,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;instead of this line:&lt;BR /&gt;(( idle_min = $(echo $idle|cut -f1 -d':') * 60 + $(echo $idle|cut -f2 -d':') ))&lt;BR /&gt;&lt;BR /&gt;try this:&lt;BR /&gt;(( idle_min = $(echo $idle|cut -f1 -d':') * 60 + $(echo ${idle#[0-9]*:0}|cut -f2 -d':'&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Feb 2007 04:40:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029560#M97777</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2007-02-21T04:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029561#M97778</link>
      <description>According to sh-posix man pages, forcing the base to be 10 is not necessary.&lt;BR /&gt;&lt;BR /&gt;In fact, I tested your script in my 11.11 box and it runs fine.&lt;BR /&gt;&lt;BR /&gt;Which shell is using in 11.11 ?&lt;BR /&gt;Have you tried several shells (ksh, sh-posix) ?</description>
      <pubDate>Wed, 21 Feb 2007 04:53:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029561#M97778</guid>
      <dc:creator>Jdamian</dc:creator>
      <dc:date>2007-02-21T04:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029562#M97779</link>
      <description>&amp;gt;Oscar: According to sh-posix man pages, forcing the base to be 10 is not necessary.&lt;BR /&gt;&lt;BR /&gt;Perhaps UNIX95 was set?&lt;BR /&gt;&lt;BR /&gt;It is hard to argue when Rita had the error message:&lt;BR /&gt;08 : The specified number is not valid for this command.&lt;BR /&gt;Of course it would be nice to know which command.  I have no problems duplicating it on 11.23:&lt;BR /&gt;./itrc_leadzero.sh[26]: 08 : The specified number is not valid for this command.&lt;BR /&gt;26     (( idle_min = $(echo $idle|cut -f1 -d':') * 60 + $(echo $idle|cut -f2 -d':') ))&lt;BR /&gt;&lt;BR /&gt;Which means you need my: typeset -LZ idle_min&lt;BR /&gt;With Peter's extra temps:&lt;BR /&gt;idle_hr=`echo ${idle} |cut -f1 -d':'`&lt;BR /&gt;idle_min=`echo ${idle} |cut -f2 -d':'`&lt;BR /&gt;idle_total=(( idle_hr * 60 + idle_min ))&lt;BR /&gt;&lt;BR /&gt;Of course bc(1) probably doesn't have this scummy C octal rule.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Feb 2007 05:08:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029562#M97779</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-02-21T05:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029563#M97780</link>
      <description>&lt;!--!*#--&gt;Hi Rita&lt;BR /&gt;Hi Dennis&lt;BR /&gt;&lt;BR /&gt;I agree Denis when he wrote that the problem might be UNIX95.&lt;BR /&gt;&lt;BR /&gt;According to sh-posix man pages:&lt;BR /&gt;&lt;BR /&gt;      If UNIX95 is defined, shell arithmetic evaluators let command,&lt;BR /&gt;      $((...)) and ((...)) recognizes interger constants beginning with 0&lt;BR /&gt;      and 0x (or 0X) as octal and hexadecimal numbers.&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Feb 2007 05:18:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029563#M97780</guid>
      <dc:creator>Jdamian</dc:creator>
      <dc:date>2007-02-21T05:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029564#M97781</link>
      <description>Try&lt;BR /&gt;&lt;BR /&gt;(( idle_min = 10#$(echo $idle|cut -f1 -d':') * 60 + 10#$(echo $idle|cut -f2 -d':') ))</description>
      <pubDate>Wed, 21 Feb 2007 05:29:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029564#M97781</guid>
      <dc:creator>Jdamian</dc:creator>
      <dc:date>2007-02-21T05:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029565#M97782</link>
      <description>Dear Rita,&lt;BR /&gt;&lt;BR /&gt;Please consider the following free advice, worth every penny.&lt;BR /&gt;&lt;BR /&gt;1) This particular wheel has been invented many times over. Please look around for existing commercial or freeware solutions.&lt;BR /&gt;It looks simple enough now, but it is probably too simple. You'll soon need exclusion lists and time ranges and stuff like that.&lt;BR /&gt;&lt;BR /&gt;2) Every Unix sysadm MUST try to aquire some awk and perl skills. Not saying you should start doing everything with those (allthough you could :-), but for your own career you MUST get going on those powerful tools.&lt;BR /&gt;&lt;BR /&gt;3) Idle killers suck... IMHO. They suck computer resources, they suck positive energy out of users, they suck at providing security, they suck admin time. They do exactly waht their name implies, but not what you want: They kill idleness and replace it with busyness. Sounds like a bad virus to me!&lt;BR /&gt;&lt;BR /&gt;4) Consider replacing the "ge" in you script with a simple "&amp;gt;". The leading zero minute field compares nicely as a string instead of numbers.&lt;BR /&gt;&lt;BR /&gt;5) Just to trigger your cusiosity consider this perl script reading the smaple input your gave:&lt;BR /&gt;&lt;BR /&gt;#perl -lne 'if (/(\d+):(\d\d)$/) { ($u,$t,$i)=split; print qq($u on  $t idle for $i) if ($1&amp;gt;0 or $2&amp;gt;30)}' tmp.txt&lt;BR /&gt;kwchow on  pts/tr idle for 0:54&lt;BR /&gt;mmak on  pts/tk idle for 1:16&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#perl -lne   -e = cmmand follows, -l=print newlines, -n=loop throug input Not printing.&lt;BR /&gt;&lt;BR /&gt;if (/(\d+):(\d\d)$/){ = Look for decimals, a colong and two decimals at the end of the line.&lt;BR /&gt;If found remember in $1 and $2 and execute block.&lt;BR /&gt;&lt;BR /&gt;($u,$t,$i)=split;  # AAyup that's what it does.&lt;BR /&gt;print qq($u on  $t idle for $i) if # conditional statement&lt;BR /&gt;($1&amp;gt;0 or $2&amp;gt;30)} # The hour not 0, or minutes greate than 30&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Feb 2007 09:20:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029565#M97782</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-02-21T09:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029566#M97783</link>
      <description>As bc(1) doesn't have this scummy octal rule; replace...&lt;BR /&gt;&lt;BR /&gt;(( idle_min = $(echo $idle|cut -f1 -d':') * 60 + $(echo $idle|cut -f2 -d':'&lt;BR /&gt;) ))&lt;BR /&gt;&lt;BR /&gt;with...&lt;BR /&gt;&lt;BR /&gt;(( idle_min = $(echo $idle|cut -f1 -d':') * 60 + $(echo $idle|cut -f2 -d':' | bc&lt;BR /&gt;) ))</description>
      <pubDate>Wed, 21 Feb 2007 11:44:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029566#M97783</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-02-21T11:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029567#M97784</link>
      <description>Sandman,&lt;BR /&gt;please see my bc solution posted at 08:58:06 &lt;BR /&gt;;-)</description>
      <pubDate>Wed, 21 Feb 2007 11:53:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029567#M97784</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2007-02-21T11:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029568#M97785</link>
      <description>&amp;gt;Oscar: According to sh-posix man pages: If UNIX95 is defined, &lt;BR /&gt;&lt;BR /&gt;On 11.23, this UNIX95 has been removed.  In all cases it: &lt;BR /&gt;... will be processed according to ISOC standard</description>
      <pubDate>Wed, 21 Feb 2007 14:40:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029568#M97785</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-02-21T14:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Script to calculate the total idle minutes</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029569#M97786</link>
      <description>Thank you all for the great support&lt;BR /&gt;&lt;BR /&gt;I found more than 1 solution, but I choose the most understanable one, the "|bc", also rewrote this script which is written few years ago in a more structured format&lt;BR /&gt;&lt;BR /&gt;Correct, I need to acquire to learn some awk knowledge &amp;amp; someone else in my team is learning Perl, so may rewrite this script in Perl later&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Rita</description>
      <pubDate>Fri, 23 Feb 2007 01:50:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-the-total-idle-minutes/m-p/5029569#M97786</guid>
      <dc:creator>Rita Li</dc:creator>
      <dc:date>2007-02-23T01:50:42Z</dc:date>
    </item>
  </channel>
</rss>

