- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Days Validation in Script or via Cron
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
09-20-2007 07:36 PM
09-20-2007 07:36 PM
I have 4 scripts A.sh , B.sh, C.sh , D.sh and would like to run them on different calender days.
A.sh [ Every working day]
B.sh [ Every weekday (NOT on Weekend & Monthend) AND After A.sh is finished successfully]
C.sh [ Every Weekend OR monthend AND After A.sh is finished successfully]
D.sh [ Every weekend OR monthend AND after C.sh is finished successfully]
This task has to be managed via cron. I am thinking of putting below validations in A.sh and run A.sh from cron. At the end of each script I am generating a script.success file, Which could help to validate file dependency. Could you please help me in putting the syntax across for day validations in UNIX. Something like below must be the last lines in A.sh :
process...
touch A.success
IF [today is mon-thu and [ -f A.success] and ! fri or last working day of month]
then
run B.sh
FI
IF [ today is Friday or last working day of month AND [ -f A.success]
then
run C.sh
FI
IF [ today is Friday or last working day of month AND [ -f C.success]
then
run D.sh
FI
Please advice the piece of code to be placed in last lines of A.sh?
Many THANKS !!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2007 11:21 PM
09-21-2007 11:21 PM
SolutionYou also need to define "working" day and "weekend". (For me, working is mon-fri and weekend is sat and sun.)
So to do what you have after each "IF":
dow=$(date +%u) # 1 - 7 mon - sun
if [ $dow -le 4 -a -f A.success -a ! last_work_day ]; then
if [ \( $dow -eq 5 -o last_work_day \) -a f A.success ]; then
if [ \( $dow -eq 5 -o last_work_day \) -a f C.success ]; then
Then write a function last_day_of_month that will compute it.
typeset -i month_day dom mm dow year
set -A month_day 31 28 31 30 31 30 31 31 30 31 30 31
function last_day_of_month {
echo "DoM: $dom"
echo "Dow: $dow"
echo "Mon: $mm"
echo "Year: $year"
if [ $mm -eq 2 ]; then # Feb
if (( year % 4 == 0 && (year % 100 != 0 || year % 400 == 0) )); then
(( month_day[1] += 1 ))
fi
fi
echo "days in month ${month_day[mm - 1]}"
return $(( dom == month_day[mm - 1] )) # 1 for true
}
dom=$(date +%d)
mm=$(date +%m);
dow=$(date +%u) # 1 - 7 mon - sun
year=$(date +%Y)
last_day_of_month
ldm=$?
echo $ldm
if [ $dow -le 4 -a -f A.success -a $ldm -eq 1 ]; then
echo B.sh
fi
if [ \( $dow -eq 5 -o $ldm -eq 1 \) -a -f A.success ]; then
echo C.sh
touch C.success
fi
if [ \( $dow -eq 5 -o $ldm -eq 1 \) -a -f C.success ]; then
echo D.sh
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2007 08:05 AM
09-22-2007 08:05 AM
Re: Days Validation in Script or via Cron
You need some way to work your script with local holidays or it will malfunction.
Also note that the local work week is different in different countries. Sun-Thursday here, Sat-Wednesday in some of the surrounding countries.
Here area few links to programs that might help with date calculations.
http://hpux.ws/merijn/caljd-2.25.sh
http://hpux.ws/merijn/caljd-2.2.pl
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2007 09:50 PM
09-24-2007 09:50 PM
Re: Days Validation in Script or via Cron
How about this function?
last_work_day
Have i missed it in first code?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2007 10:57 PM
09-24-2007 10:57 PM
Re: Days Validation in Script or via Cron
I didn't know how you defined it nor when your holidays were. But for me, Friday and simplifying to no holidays:
# handle last work day
return $(( dow <= 5 && dom == month_day[mm - 1] ||
dow == 5 && dom >= month_day[mm - 1] - 2 )) # 1 for true
That's (Friday or before) and last day of month. OR Friday and within 2 days of last day.