Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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

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
EOF2.
mailx -s "Load on $NODE" $SYS_ADMIN < sarmsg.dat
Luke Chi

![]() |
![]() |
![]() |

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