Computing.Net > Forums > Unix > unix script run from cron

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

unix script run from cron

Reply to Message Icon

Name: otherguy
Date: June 29, 2009 at 14:21:30 Pacific
OS: unix
Subcategory: General
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: June 29, 2009 at 19:03:42 Pacific
Reply:


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))
fi

begindate=$(printf "%02d/01/%d\n" $m $y)
echo $begindate

endday=$(cal $m $y|awk ' { print $NF } '| sed '/^$/d' |tail -1)

enddate=$(printf "%02d/%02d/%d\n" $m $endday $y)
echo $enddate


0

Response Number 2
Name: otherguy
Date: June 29, 2009 at 19:25:30 Pacific
Reply:

Thanks. I'll give this a try. I already knew how to embed the informix script.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: unix script run from cron

Running a shell script from cron www.computing.net/answers/unix/running-a-shell-script-from-cron/4091.html

FTP - establishing connection www.computing.net/answers/unix/ftp-establishing-connection/454.html

help on Crontab utility www.computing.net/answers/unix/help-on-crontab-utility/7917.html