Computing.Net > Forums > Unix > cron job

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.

cron job

Reply to Message Icon

Name: AndrewG1976
Date: August 10, 2005 at 19:48:04 Pacific
OS: SunOS 5.8
CPU/Ram: 440Mhz/512MB
Comment:

Hi,

I am new to Unix. Can anyone tell me how to setup a cron job to run the following sql query and email it to my email address at 12am every Monday and at 12am on the 1st day of each month?

I'd like the result to be emailed to me either in the message body or attached as a .csv file.

The queries to execute are:

LOGINS FOR LAST WEEK
Schedule: Run and email at 12am every Monday
-------------------

SELECT COUNT(USERID) "LOGINS FOR LAST WEEK"
FROM SYSTEM_SESSION_LOG S
WHERE S.SESSION_START > (SYSDATE-7)
AND S.SESSION_START < (SYSDATE)

SELECT COUNT(DISTINCT USERID) "UNIQUE LOGINS LAST WEEK"
FROM SYSTEM_SESSION_LOG S
WHERE S.SESSION_START > (SYSDATE-7)
AND S.SESSION_START < (SYSDATE)


LOGINS FOR LAST MONTH
Schedule: Run and email at 12am on the 1st day of each month
-------------

SELECT COUNT(USERID) "LOGINS FOR LAST MONTH"
FROM SYSTEM_SESSION_LOG S
WHERE S.SESSION_START > (SYSDATE-31)
AND S.SESSION_START < (SYSDATE)

SELECT COUNT(DISTINCT USERID) "UNIQUE LOGINS LAST MONTH"
FROM SYSTEM_SESSION_LOG S
WHERE S.SESSION_START > (SYSDATE-31)
AND S.SESSION_START < (SYSDATE)

The database connection info is:

DBName: Test
DBUser: System
DBPwd: system



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: August 11, 2005 at 06:31:11 Pacific
Reply:

man crontab

crontab Entry Format
A crontab file consists of lines of six fields each.The fields are separated by spaces or tabs. The first five are integer patterns that specify the following:

minute (0-59),
hour (0-23),
day of the month (1-31),
month of the year (1-12),
day of the week (0-6 with 0=Sunday).

12 am Monday ( Noon ? )

0 12 * * 1 command

12 am 1st day of the month

0 12 1 * * command


0

Response Number 2
Name: Luke Chi
Date: August 11, 2005 at 11:01:05 Pacific
Reply:

2 mailx examples for you (HP):

1.
mailx $SAFE_DIST_LIST <<EOF > /dev/null
~s "Safe - Dropped indexes not recreated by Oracle Apps patches"
~<! echo "\nThe list and the checking results are as follows:\n"
~<! cat $TMPFILE
EOF

2.
mailx -s "Load on $NODE" $SYS_ADMIN < sarmsg.dat


Luke Chi


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: cron job

Cron jobs of other users www.computing.net/answers/unix/cron-jobs-of-other-users/6557.html

cron job www.computing.net/answers/unix/cron-job/1897.html

Cron jobs www.computing.net/answers/unix/cron-jobs/1589.html