Hi
I have a task that generates list of database users every 1st day of the new month at 08:30 AM, thereafter it will be automatically be sent to me. This task is working fine, I am just trying to understand how the .csv output from crontab is being automatically send by mutt to me. I just cant find any link between mutt and crontab. They are in the same directory path.
Code:
#Get User List By Running getemployee.csh
30 08 1 * * /calc/atdmp/atdmp/ssdmp/o3user/getemployee.csh > /dev/null
Here, it connects to the db to get user list and output into employee_$execdate.csv
Code:
[atdmp@ATDMP2 o3user]$ cat getemployee.csh
#!/bin/csh
#DB Link
set link_name = 'SSDB'
#Local DB user and password
set db_user = 'atdmp'
set db_pass = 'atdmp'
set execdate = `date +%m%Y`
set TMP=/calc/atdmp/atdmp/ssdmp/o3user/employee_$execdate.csv
#------Create DB Link for ATLAS DB -------
$ORACLE_HOME/bin/sqlplus -s $db_user/$db_pass <<EOF>>/dev/null
create database link $link_name
connect to atlas
identified by atlas
using 'SSDB3';
set echo off heading off trimspool on linesize 500 pagesize 0 term off feedback off trimout on NULL ""
spool $TMP
SELECT lpad(EMPLOYEENUMBER,6,'0') ||','||
VE_EMPLOYEE.EMPLOYEENAME||','||
VE_EMPLOYEE.SECURITYGROUPCODE||','||
VE_EMPLOYEE.SECURITYGROUPNAME||','||
VE_EMPLOYEE.JOBCODE||','||
VE_EMPLOYEE.JOBNAME||','||
to_char(VE_EMPLOYEE.UPDATEDATETIME,'dd/mm/yyyy hh24:mi')
FROM ATLAS.VE_EMPLOYEE@$link_name VE_EMPLOYEE
WHERE (VE_EMPLOYEE.EMPLOYEENUMBER<>0
And VE_EMPLOYEE.EMPLOYEENUMBER<>453303
And VE_EMPLOYEE.EMPLOYEENUMBER<>99999999
And VE_EMPLOYEE.EMPLOYEENUMBER<>9999
And VE_EMPLOYEE.EMPLOYEENUMBER<>111111)
ORDER BY lpad(EMPLOYEENUMBER,6,'0');
spool off
EOF
echo "--------End Query --------"
#-------Drop Database Link--------
$ORACLE_HOME/bin/sqlplus $db_user/$db_pass <<EOF
drop database link $link_name;
EOF
[atdmp@ATDMP2 o3user]$
sendfile* uses mutt to email me the file and then delete the file after sending
Code:
[atdmp@ATDMP2 o3user]$
[atdmp@ATDMP2 o3user]$ ls -l
total 16
-rwxrwxr-x 1 atdmp calc 1287 Jan 12 2012 getemployee.csh*
-rw-rw-r-- 1 atdmp calc 75 Oct 1 2012 msg.txt
-rw-rw-r-- 1 atdmp calc 394 Jan 12 2012 output
-rwxrwxr-x 1 atdmp calc 235 Jan 7 17:08 sendfile*
[atdmp@ATDMP2 o3user]$
[atdmp@ATDMP2 o3user]$
[atdmp@ATDMP2 o3user]$
[atdmp@ATDMP2 o3user]$ cat sendfile
mutt -s "O3 User List" -a /home/calc/atdmp/atdmp/ssdmp/o3user/employee*.csv Amos.Lee-YP@ssg.renesas.com < /home/calc/atdmp/atdmp/ssdmp/o3user/msg.txt
rm /calc/atdmp/atdmp/ssdmp/o3user/employee*.csv
[atdmp@ATDMP2 o3user]$
Other non important details for output and msg.txt
Code:
[atdmp@ATDMP2 o3user]$ cat output
--------End Query --------
SQL*Plus: Release 9.2.0.7.0 - Production on Thu Jan 12 16:49:29 2012
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Release 9.2.0.7.0 - Production
JServer Release 9.2.0.7.0 - Production
SQL>
Database link dropped.
SQL> Disconnected from Oracle9i Release 9.2.0.7.0 - Production
JServer Release 9.2.0.7.0 - Production
[atdmp@ATDMP2 o3user]$
[atdmp@ATDMP2 o3user]$
[atdmp@ATDMP2 o3user]$ cat msg.txt
This file generates list of users in ATLAS DB...
Date created: 12-01-2012
[atdmp@ATDMP2 o3user]$
My question is, how is it possible for sendfile* to know and automatically send employee_$execdate.csv to me after getemployee.csh* has generated employee_$execdate.csv? Just trying to understand and learn... Thanks