- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to get first working day of the month
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-05-2007 03:14 AM
12-05-2007 03:14 AM
I am executing one .scr script from 1-5(MON-FRIDAY)at 8:00 then 8:15 and so on. But it should execute one other fun on 1st working day of every month and if time is < 8:10.
I am having existing logic but it will work only 1st of the month it is working day.
From working day i mean (MON to FRI).
Existing logic in .scr file:
d means day, hr - hour, FIRSTRUNHOUR=8
*************************************
if [ $d -ne 1 -o $hr -ne $FIRSTRUNHOUR -o $min -ge 10 ]; then
break;
else
perform specific fun.
fi;
This 3rd of dec it did not execute.
Can some one suggest that how to do this?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 03:21 AM
12-05-2007 03:21 AM
Re: How to get first working day of the month
More clarification on below query. I am running this cron everyday. But if this is first working day of the month it will do some extra function at first run of the cron means at 8:00. In second run 8:15 it should not perform the funtion, as mentioned in existing logic if it is > 8:10 the break.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 04:10 AM
12-05-2007 04:10 AM
Re: How to get first working day of the month
Note that in the CRONTAB, you have the possibility to specify day of the month. Why dont you use this to schedule a script accordingly.
#*******************************************************************************
# min|hour |day |month|day |script
# | |of mo| |of wk|
#----|-----|-----|-----|-----|--------------------------------------------------
00 08 1 * * /home/yogeeraj/myscript.sh 1>/home/yogeeraj/logfiles/output-myscript.crn 2>/home/yogeeraj/logfiles/error-myscript.crn
#*******************************************************************************
hope this helps!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 04:10 AM
12-05-2007 04:10 AM
Re: How to get first working day of the month
Note that in the CRONTAB, you have the possibility to specify day of the month. Why dont you use this to schedule a script accordingly.
#*******************************************************************************
# min|hour |day |month|day |script
# | |of mo| |of wk|
#----|-----|-----|-----|-----|--------------------------------------------------
00 08 1 * * /home/yogeeraj/myscript.sh 1>/home/yogeeraj/logfiles/output-myscript.crn 2>/home/yogeeraj/logfiles/error-myscript.crn
#*******************************************************************************
hope this helps!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 04:15 AM
12-05-2007 04:15 AM
SolutionA combination of cal and awk will return you the date of the first monday. If date on Monday falls on 3, that means to say saturday and sunday were 1st and 2nd. If 1st was as on Sunday, Monday would be 2nd. You can check the value of date of first monday using the below command.
first_monday=cal|awk '{print $2}'|head -4|tail -1
For all other days you can use the below logic.
day=$(date '+%d')
if [[ $day -eq 1 ]]
then
echo "execute for the 1st"
fi
Thanks,
Srikanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 04:22 AM
12-05-2007 04:22 AM
Re: How to get first working day of the month
All the best
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 08:55 AM
12-05-2007 08:55 AM
Re: How to get first working day of the month
Do a search for caljd.sh (or caljd.pl). This utility will easily handle your needs AND handle holidays.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2007 09:22 PM
12-05-2007 09:22 PM
Re: How to get first working day of the month
Very thanks for your valuable replies.
Actually thing is that i can not set cron for this otherwise it would be very tough to handle thing i have to write logic only.
I am quite convinced with Srinikant reply.
I am trying to implement it. I will come back in case of any issues if incounter.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2007 12:37 AM
12-06-2007 12:37 AM
Re: How to get first working day of the month
Actually i want bit change in my query,
in everymonth i have to decide that among
1 or 2 or 3 which is first working day.
I have to put this logic in script that will be executed through cron everyday from 8 to 16.
Can you suggest anything?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2007 12:52 AM
12-06-2007 12:52 AM
Re: How to get first working day of the month
Put a simple if condition to check combination of day and date.
date +%a return the day of the week and
date +%d return the date as '01','02', '03' etc.
Hope this helps.
Regards,
Srikanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2007 01:43 AM
12-06-2007 01:43 AM
Re: How to get first working day of the month
We can only tell you the first weekday. You would have to translate "working" to your locale.
As Srikanth says, with a slight correction:
dow=$(date +%u) day of the week 1 M .. 7 S
dom=$(date +%d) day of month
So for first non-weekend day:
if [ $dom -eq 1 -a $dow -lt 6 -o
$dom -lt 4 -a $dow -eq 1 ]; then
echo "first workday in month"
else ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2007 03:00 AM
12-06-2007 03:00 AM
Re: How to get first working day of the month
Thanks a lot it will work for me.
Many thanks