- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Retrieve week number and week day for a input ...
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
Forums
Discussions
Discussions
Discussions
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
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
12-27-2005 06:25 PM
12-27-2005 06:25 PM
I am writing a small shell script, and based on input date, it want to get the weeknum and weekday. One more thing, i want the week day starting from Saturday.
I have
----------------------------------------
%U Week number of the year (Sunday as the first day of the week)
%V Week number of the year (Monday as the first day of the week)
%w Weekday as a one-digit decimal number [0-6 (Sunday- Saturday)].
%W Week number of the year (Monday as the first day of the week)
---------------------------------------------
Please advice,
AJi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2005 06:38 PM
12-27-2005 06:38 PM
Re: Retrieve week number and week day for a input date
I would really recommend A.Clay Stephenson's caljd series of scripts at:
http://hpux.ws/merijn/caljd-2.23.sh
http://hpux.ws/merijn/caljd-2.2.pl
If you really want to work out the day of the week search for Zeller's rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2005 06:44 PM
12-27-2005 06:44 PM
Re: Retrieve week number and week day for a input date
Please can you verify the url provided. I cant access the webpage.
As i would like to know whether there is any function in UNIX that is going to replace MOD
Thanks for the support,
AJi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2005 07:05 PM
12-27-2005 07:05 PM
Re: Retrieve week number and week day for a input date
Check the Mirror hp-ux page of H Merjin.
http://mirrors.develooper.com/hpux/stats.html
At the bottom check for the scripts.
Hope it helps ,
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2005 07:11 PM
12-27-2005 07:11 PM
Re: Retrieve week number and week day for a input date
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2005 08:05 PM
12-27-2005 08:05 PM
Re: Retrieve week number and week day for a input date
Revert when someone find it.
-Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2005 08:39 PM
12-27-2005 08:39 PM
Re: Retrieve week number and week day for a input date
Thanks for the reply,
My purpose of the scripts is to include within my backup script to find alternate weeks.
Each week we backup up data to particular FileSystem FS, next week we backup to another FS.
I am trying to develop a script for this fuctionality based on date as input.
I thought of getting it work based on week number, but if there are 53 weeks in a year, the logic does not work.
Any idea???
AJi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2005 08:58 PM
12-27-2005 08:58 PM
Re: Retrieve week number and week day for a input date
Schedule script executing with cron tab on specific time on every week.
Try to change to File system selection based on a variable or file availablity.
# touch /etc/filesystemselect
# cat > /etc/filesystemselect
FS=1
In the script,
if [[ -f /etc/filesystemselect ]]
then
. /etc/filesystemselect
if [[ ${FS} -eq 1 ]]
then
# Action with file system one
# change contents of /etc/fsselect
echo "FS=2" > /etc/filesystemselect
elif [[ ${FS} -eq 2 ]]
then
# Action with file system two
# change contents of /etc/fsselect
echo "FS=1" > /etc/filesystemselect
fi
else
echo "ERROR: Which file system to be selected"
exit 1
fi
It will do your requirement.
Note: /etc/filesystemselect must be there.
-Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2005 09:10 PM
12-27-2005 09:10 PM
Re: Retrieve week number and week day for a input date
How will it know which week to do the switch in filesystem.
Say My week starts on SAT-FRI
Take the following example,
17th - 23rd Dec 2005
> Backup should go to /prod1 filesystem.
24th - 30th Dec 2005
> Backup should go to /prod2 filesystem.
31th Dec 2005 - 6th Jan 2006
> Backup should go to /prod1 filesystem.
Please advice,
AJi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2005 11:20 PM
12-27-2005 11:20 PM
Solutionperhaps you can figure out which fs to use with the help of Stephenson's script and a bit of convention: enter the correct path to Stephenson's script in the script below and try executing that with three parameters for month, day, and year, e.g. for 31 DEC 2005:
# ./find_fs.sh 12 31 2005
which should produce
12 31 2005 should use prod1
The convention is that you cannot enter a date before Dec 23 2005.
#/usr/bin/sh
CALJD=./caljd-2.23.shi # enter path to script
CURRENT_JD=$($CALJD $1 $2 $3)
if [ "$#" != 3 ]
then
echo wrong number of parameters
exit 1
fi
# Starting point, first day is 23 dec 2005
DAY_ONE_JD=2453722
# How many days since start
PASSED_DAYS=$(( $CURRENT_JD - $DAY_ONE_JD))
# in chunks of fortnights...
let DAY_NUM=PASSED_DAYS%14
case $DAY_NUM in
0|1|2|3|4|5|6) FS=1;;
7|8|9|10|11|12|13) FS=2;;
esac
echo $1 $2 $3 should use prod$FS
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2005 01:02 AM
12-28-2005 01:02 AM
Re: Retrieve week number and week day for a input date
Thanks for the best support,
Its works fine.
I forgot to mention one more thing. Every thursday we keep a weekly backup on different FSWEEK1 and FSWEEK2.
For eg
22-dec-2005 - FSWEEK1
29-dec-2005 - FSWEEK2
5-jan-2006 - FSWEEK1
and so on.
Please suggest me script to include this also.
Waiting for your expertize suggestions
AJi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2005 01:33 AM
12-28-2005 01:33 AM
Re: Retrieve week number and week day for a input date
you can try the script with this extension:
#/usr/bin/sh
FULL=""
CALJD=./caljd-2.23.sh
CURRENT_JD=$($CALJD $1 $2 $3)
if [ "$#" != 3 ]
then
echo wrong number of parameters
exit 1
fi
# Starting point, first day is 23 dec 2005
DAY_ONE_JD=2453722
# How many days since start
PASSED_DAYS=$(( $CURRENT_JD - $DAY_ONE_JD))
# in chunks of fortnights...
let DAY_NUM=PASSED_DAYS%14
case $DAY_NUM in
0|1|2|3|4|5|6) FS=1;;
7|8|9|10|11|12|13) FS=2;;
esac
echo $1 $2 $3 should use prod$FS
case $DAY_NUM in
5) FULL=FSWEEK1;;
12) FULL=FSWEEK2;;
esac
if [ "${FULL}X" != "X" ]
then
# put code for full backup here
echo use full bacup on $FULL
fi
But I suggest you do a lot of testing before letting the above control your backup!
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2005 08:14 AM
12-28-2005 08:14 AM
Re: Retrieve week number and week day for a input date
Here's a simple perl script that returns a three-item string denoting the day-of-the-week (1-7 where 1=Monday), the number of the week within the month (1-5) and the week-number (1-53) of the year.
#!/usr/bin/perl
use strict;
use warnings;
use Date::Calc qw( Decode_Date_US Day_of_Week Week_of_Year );
die "Usage: $0 MMDDYYYY\n" unless @ARGV;
my ($year, $month, $day);
if (($year, $month, $day) = Decode_Date_US($ARGV[0])) {
print Day_of_Week ($year, $month, $day), " ",
int (($day + Day_of_Week ($year, $month, 1) - 2) / 7) + 1, " ",
scalar Week_of_Year($year, $month, $day), "\n";
}
1;
Run the script by passing a US-format (MMDDYYYY) date either with or without delimiters:
# ./daynums 01/01/2005
6 1 53
...since 01/01/2005 was a Saturday (6) in the first (1) week of January but is reckoned as the LAST (53rd) week of the preceeding year, since no Monday had yet occured in 2005.
# ./daynums 12/28/2005
3 5 52
...a Wednesday (day-3) of the fifth (5) week of the month and the 52nd week of the year.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2006 07:16 PM
02-05-2006 07:16 PM