- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Scripting problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2007 08:23 AM
тАО08-23-2007 08:23 AM
there are 4 users and one of them is to be selected each week, like this:
week 1: user1
week 2: user2
week 3: user3
week 4: user4
week 5: user1
week 6: user2
and so on, repeating user1, user2, user3 and user4.
Any idea how to script this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2007 08:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2007 08:35 AM
тАО08-23-2007 08:35 AM
Re: Scripting problem
#!/usr/bin/sh
typeset -i WEEK=1
typeset -i USERNUM=1
while true
do
for USERNUM in 1 2 3 4
do
echo "week ${WEEK}: user${USERNUM}"
WEEK=$((${WEEK}+1))
done
done
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2007 08:37 AM
тАО08-23-2007 08:37 AM
Re: Scripting problem
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:
# date +%U
# date +%W
For example:
# let X=$(date +%W)%4;echo ${X}
2
...or the second group. More directly based on your example this is simply week-34.
# echo $(date +%W)
34
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2007 08:50 AM
тАО08-23-2007 08:50 AM
Re: Scripting problem
----------------------------------------
#!/usr/bin/sh
export PATH=${PATH}:/usr/local/bin
typeset -i WK=0
typeset USER=""
WK=$(( (($(caljd.sh) + 1) / 7) % 4 ))
((WK += 1))
U="user${WK}"
echo "User for this week is ${U}"
exit 0
------------------------------------------
Use the attached script, caljd.sh to solve virtually any date problem you can imagine. Invoke as caljd.sh -u for full usage.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2007 08:59 AM
тАО08-23-2007 08:59 AM
Re: Scripting problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2007 09:17 AM
тАО08-23-2007 09:17 AM
Re: Scripting problem
WK=$(( (($(caljd.sh) + 1) / 7) % 4 ))
to
WK=$(( (($(caljd.sh) - 4) / 7) % 4 ))
and your weeks will begin on Friday.
- Tags:
- caljd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2007 03:23 PM
тАО08-23-2007 03:23 PM
Re: Scripting problem
For any given time is it run it will print the corresponding cycle number, starting a fresh one every Friday.
Optionally provide it a time (unix time in seconds :^) and it will print the cycle for that time.
Suggested solution:
perl -le '$t=shift||time;$t+=86400*((11-(localtime($t))[6])%7);$w=int($t/(7*86400)); print 1+$w%4'
So it takes a time $t from clock or optional argument.
Adds to that a number of days worth of seconds to get to the next Friday.
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.
Next divide by the number of seconds in a week to get a (psuedo) week number in $w
Finally a 'mod 4' on that give the user number.
To make a week start on Saturday, change the 11 to a 12.
btw...
To assure me of the math, and to get sample times I used:
Suggested verification:
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)}'
This generates:
2 1188011902 1188530302 Fri Aug 24 23:18:22 2007
2 1188098302 1188530302 Sat Aug 25 23:18:22 2007
:
2 1188530302 1188530302 Thu Aug 30 23:18:22 2007
3 1188616702 1189135102 Fri Aug 31 23:18:22 2007
3 1188703102 1189135102 Sat Sep 1 23:18:22 2007
:
3 1189135102 1189135102 Thu Sep 6 23:18:22 2007
4 1189221502 1189739902 Fri Sep 7 23:18:22 2007
Grins,
Hein.
- Tags:
- Perl