February 18, 2009

UNIX case study - 10

Create Calendar
You can create a calendar of 365 days starting from a given day. The days in each month will be grouped together, separated by comma and enclosed in apostrophe.


sh /root/calendar.sh '2002-01-01'

#!/bin/sh
mysql -e"drop table if exists test.mycalendar;"
mysql -e"create table test.mycalendar (id int not null auto_increment, dateval date, primary key (id));"

for (( i = 0 ; i < 730 ; i++ ))
do
mysql -e"insert into test.mycalendar (dateval) select '$1' + interval $i day;"
done

mysql -e"select group_concat(concat('to_days(', '\'',dateval,'\')') order by dateval) as '' from test.mycalendar group by extract(year_month from dateval);" | sort

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.