Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to create a unix script that will run on the first of every month as a cron job to pull a report (infomix sql query) for the previous month. I know how to build the query, that's not the problem. The problem I'm having is how to execute the script so it knows to start (go back) to the first day of the previous month and end on the last day regardless of the number of days in the month.

If you plan on using a shell script to determine first and last date of the previous month, you will have to embed your informx scrpt in a shell script. These two links will tell you how:http://www.computing.net/answers/un...
http://www.computing.net/answers/un...This script determines last month's begin and end dates:
#!/bin/ksh
m=$(date '+%m') m=$((m-=1)) y=$(date '+%Y') if [[ m -eq 0 ]] then # january m=12 y=$((y-=1)) fibegindate=$(printf "%02d/01/%d\n" $m $y)
echo $begindateendday=$(cal $m $y|awk ' { print $NF } '| sed '/^$/d' |tail -1)
enddate=$(printf "%02d/%02d/%d\n" $m $endday $y)
echo $enddate

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |