<?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: Scripting problem in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059521#M94470</link>
    <description>I don't know how you're determining the week, but for a static list:&lt;BR /&gt;&lt;BR /&gt;for i in 1 2 3 4 5 6 7 8 9; do &lt;BR /&gt;echo week $i: user$(($(((i - 1) % 4)) + 1));&lt;BR /&gt;done</description>
    <pubDate>Thu, 23 Aug 2007 15:35:15 GMT</pubDate>
    <dc:creator>Jonathan Fife</dc:creator>
    <dc:date>2007-08-23T15:35:15Z</dc:date>
    <item>
      <title>Scripting problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059520#M94469</link>
      <description>I have a problem I need to script - &lt;BR /&gt;&lt;BR /&gt;there are 4 users and one of them is to be selected each week, like this:&lt;BR /&gt;&lt;BR /&gt;week 1:  user1&lt;BR /&gt;week 2:  user2&lt;BR /&gt;week 3:  user3&lt;BR /&gt;week 4:  user4&lt;BR /&gt;week 5:  user1&lt;BR /&gt;week 6:  user2&lt;BR /&gt;&lt;BR /&gt;and so on, repeating user1, user2, user3 and user4.&lt;BR /&gt;&lt;BR /&gt;Any idea how to script this?&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Aug 2007 15:23:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059520#M94469</guid>
      <dc:creator>dictum9</dc:creator>
      <dc:date>2007-08-23T15:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059521#M94470</link>
      <description>I don't know how you're determining the week, but for a static list:&lt;BR /&gt;&lt;BR /&gt;for i in 1 2 3 4 5 6 7 8 9; do &lt;BR /&gt;echo week $i: user$(($(((i - 1) % 4)) + 1));&lt;BR /&gt;done</description>
      <pubDate>Thu, 23 Aug 2007 15:35:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059521#M94470</guid>
      <dc:creator>Jonathan Fife</dc:creator>
      <dc:date>2007-08-23T15:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059522#M94471</link>
      <description>One method...&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset -i WEEK=1&lt;BR /&gt;typeset -i USERNUM=1&lt;BR /&gt;&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;  for USERNUM in 1 2 3 4&lt;BR /&gt;  do&lt;BR /&gt;    echo "week ${WEEK}: user${USERNUM}"&lt;BR /&gt;    WEEK=$((${WEEK}+1))&lt;BR /&gt;  done&lt;BR /&gt;done</description>
      <pubDate>Thu, 23 Aug 2007 15:35:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059522#M94471</guid>
      <dc:creator>Jeff_Traigle</dc:creator>
      <dc:date>2007-08-23T15:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059523#M94472</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;If I understand correctly, you could use the week number (see the 'date' manpages) to rotate through.  Depending on your choice of when a week begins (Sunday or Monday) use either:&lt;BR /&gt;&lt;BR /&gt;# date +%U&lt;BR /&gt;# date +%W&lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;# let X=$(date +%W)%4;echo ${X}&lt;BR /&gt;2&lt;BR /&gt;&lt;BR /&gt;...or the second group.  More directly based on your example this is simply week-34.&lt;BR /&gt;&lt;BR /&gt;# echo $(date +%W)             &lt;BR /&gt;34&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Aug 2007 15:37:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059523#M94472</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-08-23T15:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059524#M94473</link>
      <description>Using date +%U, +%V, or +%W can give somewhat screwy results at the end/beginning of the year. I assume that you will run some sort of cronjob at the same time each week.&lt;BR /&gt;&lt;BR /&gt;----------------------------------------&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;export PATH=${PATH}:/usr/local/bin&lt;BR /&gt;typeset -i WK=0&lt;BR /&gt;typeset USER=""&lt;BR /&gt;WK=$(( (($(caljd.sh) + 1) / 7) % 4 ))&lt;BR /&gt;((WK += 1))&lt;BR /&gt;U="user${WK}"&lt;BR /&gt;echo "User for this week is ${U}"&lt;BR /&gt;exit 0&lt;BR /&gt;------------------------------------------&lt;BR /&gt;Use the attached script, caljd.sh to solve virtually any date problem you can imagine. Invoke as caljd.sh -u for full usage.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Aug 2007 15:50:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059524#M94473</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-08-23T15:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059525#M94474</link>
      <description>OK.. The week begins on Fridays.&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Aug 2007 15:59:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059525#M94474</guid>
      <dc:creator>dictum9</dc:creator>
      <dc:date>2007-08-23T15:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059526#M94475</link>
      <description>In that case change this line:&lt;BR /&gt;&lt;BR /&gt;WK=$(( (($(caljd.sh) + 1) / 7) % 4 ))&lt;BR /&gt;&lt;BR /&gt;to&lt;BR /&gt;&lt;BR /&gt;WK=$(( (($(caljd.sh) - 4) / 7) % 4 ))&lt;BR /&gt;&lt;BR /&gt;and your weeks will begin on Friday.&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Aug 2007 16:17:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059526#M94475</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-08-23T16:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059527#M94476</link>
      <description>Just being a little silly, but here is a direct calculation using perl:&lt;BR /&gt;&lt;BR /&gt;For any given time is it run it will print the corresponding cycle number, starting a fresh one every Friday.&lt;BR /&gt;Optionally provide it a time (unix time in seconds :^) and it will print the cycle for that time.&lt;BR /&gt;&lt;BR /&gt;Suggested solution:&lt;BR /&gt;&lt;BR /&gt;perl -le '$t=shift||time;$t+=86400*((11-(localtime($t))[6])%7);$w=int($t/(7*86400)); print 1+$w%4'&lt;BR /&gt;&lt;BR /&gt;So it takes a time $t from clock or optional argument.&lt;BR /&gt;Adds to that a number of days worth of seconds to get to the next Friday.&lt;BR /&gt;It does that by taking the day-of-the-week number returned by localtime in its element 6 and subtracting that from 11 modulo 7.&lt;BR /&gt;Next divide by the number of seconds in a week to get a (psuedo) week number in $w&lt;BR /&gt;Finally a 'mod 4' on that give the user number.&lt;BR /&gt;To make a week start on Saturday, change the 11 to a 12.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;btw... &lt;BR /&gt;To assure me of the math, and to get sample times I used:&lt;BR /&gt;&lt;BR /&gt;Suggested verification:&lt;BR /&gt;&lt;BR /&gt;perl -le '$x=time; for (1..40){$x+=86400;$t=$x+86400*((11-(localtime($x))[6])%7);$w=int($t/(7*86400));$u=1+$w%4; print "$u $x $t ", scalar localtime($x)}'  &lt;BR /&gt;&lt;BR /&gt;This generates:&lt;BR /&gt;2 1188011902 1188530302 Fri Aug 24 23:18:22 2007&lt;BR /&gt;2 1188098302 1188530302 Sat Aug 25 23:18:22 2007&lt;BR /&gt;: &lt;SNIP&gt;&lt;BR /&gt;2 1188530302 1188530302 Thu Aug 30 23:18:22 2007&lt;BR /&gt;3 1188616702 1189135102 Fri Aug 31 23:18:22 2007&lt;BR /&gt;3 1188703102 1189135102 Sat Sep  1 23:18:22 2007&lt;BR /&gt;: &lt;SNIP&gt;&lt;BR /&gt;3 1189135102 1189135102 Thu Sep  6 23:18:22 2007&lt;BR /&gt;4 1189221502 1189739902 Fri Sep  7 23:18:22 2007&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Grins,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SNIP&gt;&lt;/SNIP&gt;</description>
      <pubDate>Thu, 23 Aug 2007 22:23:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-problem/m-p/4059527#M94476</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-08-23T22:23:26Z</dc:date>
    </item>
  </channel>
</rss>

