- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Report script
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
тАО10-06-2010 10:31 PM
тАО10-06-2010 10:31 PM
New to the scripting thing.
I have been asked to setup a report script. Calling report is not an issue. but they want diffrent things for diffrent days.
the requirement is this.
Check for first sunday of the year.
check for first sunday in june.
check for first sunday of the month
check for sunday of week.
I was thinking of using a case statment. for this.
But the problem is i am not sure of how to check for the date in each of these instances.
I was thinking of using this command.
date "+ %U:%m/%d:%C%y:%A:%M:%S"
then grepping the information i needed.
Am i on the right track.
Solved! Go to Solution.
- Tags:
- date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2010 11:12 PM
тАО10-06-2010 11:12 PM
Re: Report script
You don't have to use grep. Just assign the individual date elements to variables, and then you can use them in case or if/then/else comparisions as much as you wish.
For example:
MONTHNR=$(date +%m) # two digits: 00...12
DAYOFMONTH=$(date +%d) # 00...31
DAYOFWEEK=$(date +%w) # Sunday = 0, Saturday = 6
If you're running the report scripts from crontab, note that it can run things on a particular day of the week.
> check for sunday of week.
Just set a cron job to run on Sundays only.
For example, to run a script at 04:00 on Sundays, the cron job entry would be:
00 04 * * 0 /somewhere/script.sh
Or using the variables defined above:
if [ "$DAYOFWEEK" = 0 ]; then
# create report
fi
> Check for first sunday of the year.
If it's Sunday, and the month is January, and the day-of-month number is between 1 and 7 (inclusive), it must be the first Sunday of the year, right?
Using the variables defined above:
if [ "$DAYOFWEEK" = 0 -a "$MONTHNR" = "01" -a "$DAYOFMONTH" -ge 1 -a "$DAYOFMONTH" -le 7 ]; then
# create report
fi
You can get the first Sunday of June from the above by just adjusting the month number.
First Sunday of any month: just leave out the test for the month number.
if [ "$DAYOFWEEK" = 0 -a "$DAYOFMONTH" -ge 1 -a "$DAYOFMONTH" -le 7 ]; then
# create report
fi
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2010 11:26 PM
тАО10-06-2010 11:26 PM
Re: Report script
I was looking at something like this.
DAT=`date "+ %m:%w:%C%y:%A"`
echo $DAT
case $DAT in
00:00:2010:Sunday| echo test1;;
06:00:2010:Sunday| echo test2;;
01|02|03|04|05|07|08|09|10|11|12:00:2010:Sunday| echo test3;;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2010 11:45 PM
тАО10-06-2010 11:45 PM
Re: Report script
I was looking at something like this.
DAT=`date "+ %m:%w:%C%y:%A"`
DAT_month=`date "+ %m"`
DAT_day=`date "+ %w"`
DAT_year=`date "+ %C%y"`
DAT_day_name=`date "+ %A"`
echo $DAT
case $DAT in
01:00:$DAT_year:Sunday) echo "test1";;
06:00:$DAT_year:Sunday) echo "test2";;
01|02|03|04|05|07|08|09|10|11|12:00:$DAT_year:Sunday) echo "test3";;
02|03|04|05|07|08|09|10|11|12:00:$DAT_year:Sunday) echo "test4";;
10:4:2010:Thursday) echo "test5";;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-07-2010 12:58 AM
тАО10-07-2010 12:58 AM
Re: Report script
my echo test5 does.
DAT=`date "+%m:%w:%C%y:%A"`
DAT_month=`date "+%m"`
DAT_day=`date "+%w"`
DAT_year=`date "+%C%y"`
DAT_day_name=`date "+%A"`
echo $DAT
case $DAT in
01:00:$DAT_year:Sunday) echo "test1";; #first sunday of the year
06:00:$DAT_year:Sunday) echo "test2";; #First sunday of June
02|03|04|05|07|08|09|10|11|12:00:$DAT_year:Sunday) echo "test3";; #First Sunday of Month
02|03|04|05|07|08|09|10|11|12:00:$DAT_year:Sunday) echo "test4";; #all other sunday
$DAT_month:1|2|3|4|5|6:$DAT_year:Monday|Teusday|Wednesday|Thursday|Friday|Saturday) echo "test4";; #all other d
ays
$DAT_month:$DAT_day:$DAT_year:$DAT_day_name) echo "test5";;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-07-2010 01:40 AM
тАО10-07-2010 01:40 AM
Re: Report script
Why do you think pattern matching or regular expressions or even EREs are easier to understand than procedural programming, like in C or even COBOL?
>DAT_year=`date "+%C%y"`
Why not use just the Y2K format "+%Y"?
You do know that asking for the time in N separate calls is gong to get you into trouble around midnight?
>02|03|04|05|07|08|09|10|11|12:00:$DAT_year:Sunday) echo "test3";; #First Sunday
This is going to match $DAT with the strings:
02, 03, ... 11 or 12:10:$DAT_years:Sunday.
If you were using EREs, you could use () to enclose the various months.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-07-2010 02:22 AM
тАО10-07-2010 02:22 AM
Re: Report script
First time doing this stuff. I am just reading and putting this together as i go and testing to see if it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-07-2010 05:12 PM
тАО10-07-2010 05:12 PM
Re: Report script
I use this crontab entry to run a job on the first Sunday of the month:
0 0 1 * * at -f myscript 03:45 sun
This will run myscript at 3:45am on the first Sunday of every month.
In your case, myscript only has to work out what it needs to run.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2010 12:39 AM
тАО10-08-2010 12:39 AM
Re: Report script
i had also this issue, i am using following
scripts (found in the net):
script to search:
weekselector.sh or weekselector
requirement:
datecalc.sh or datecalc
regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2010 01:13 AM
тАО10-08-2010 01:13 AM
SolutionHere is my proposal based on the fact that when you execute the command "cal
#!/usr/bin/ksh
function get_first_sunday
{
typeset month=$1 year=$2
typeset -Z02 first_sunday=$( cal $month $year | awk 'NR == 3 { print $NF }' )
print "Sun" $year $month $first_sunday
}
typeset wday month year
typeset -Z02 mday
date +'%a %m %e %Y' | read wday month mday year
typeset first_sunday_of_the_year=$( get_first_sunday 01 $year )
typeset first_sunday_of_june=$( get_first_sunday 06 $year )
typeset first_sunday_of_the_month=$( get_first_sunday $month $year )
case "$wday $year $month $mday" in
"$first_sunday_of_the_year")
print "First sunday of the year"
;;
"$first_sunday_of_june")
print "First sunday of June"
;;
"$first_sunday_of_the_month")
print "First sunday of the month"
;;
Sun*)
print "Sunday"
;;
esac
Cheers,
Jean-Philippe