LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-08-2014, 09:59 PM   #1
hahnhahnhahn
LQ Newbie
 
Registered: Sep 2013
Posts: 6

Rep: Reputation: Disabled
Trying to understand how Mutt and Crontab works


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
 
Old 01-08-2014, 11:01 PM   #2
sgosnell
Senior Member
 
Registered: Jan 2008
Location: Baja Oklahoma
Distribution: Debian Stable and Unstable
Posts: 1,964

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
It's hard-coded.
Code:
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
It just uses regular expressions to expand employee*.csv. It will send every file that has the pattern employee*.csv, where the asterisk means any characters, and any number of them. Removing the file is key here, otherwise you would get the non-removed files already sent, and resent every day.

The link between chron and mutt is that chron runs your script at the specified times. I'm not sure where sendfile is called, perhaps another cronjob.

Last edited by sgosnell; 01-08-2014 at 11:11 PM.
 
Old 01-08-2014, 11:41 PM   #3
hahnhahnhahn
LQ Newbie
 
Registered: Sep 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sgosnell View Post
It's hard-coded.
Code:
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
It just uses regular expressions to expand employee*.csv. It will send every file that has the pattern employee*.csv, where the asterisk means any characters, and any number of them. Removing the file is key here, otherwise you would get the non-removed files already sent, and resent every day.

The link between chron and mutt is that chron runs your script at the specified times. I'm not sure where sendfile is called, perhaps another cronjob.
Ah! Here it is... in root, the cronjob that called sendfile....Thanks!

Code:
[root@ATDMP2 ~]# find -name sendfile
[root@ATDMP2 ~]#
[root@ATDMP2 ~]#
[root@ATDMP2 ~]# find /etc -name sendfile
[root@ATDMP2 ~]# find / -name 'sendfile'
/home/calc/atdmp/atdmp/ssdmp/o3user/sendfile
[root@ATDMP2 ~]#
[root@ATDMP2 ~]#
[root@ATDMP2 ~]#
[root@ATDMP2 ~]# find -name sendfile*
[root@ATDMP2 ~]#
[root@ATDMP2 ~]# crontab -l
*/6 * * * * /usr/sbin/ntpdate -Bus 138.140.100.254 2>&1 >/dev/null

#Send Snap Shot of Marking lot data, created:21-06-2010, AI
# Removed 27-06-2011, not in use anymore
#35 8 * * * /calc/atdmp/atdmp/MarkingLotTrace/sendfile.sh 2>&1 >/dev/null

#Send system check to administrator
30 01,08,16 * * * /calc/atdmp/atdmp/tools/email_dsk_chk.sh 2>&1 >/dev/null

#Send O3 User List to Admin
35 8 1 * * /home/calc/atdmp/atdmp/ssdmp/o3user/sendfile 2>&1> /dev/null

[root@ATDMP2 ~]#
 
  


Reply

Tags
mutt


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to understand how Ethernet works resetreset Linux - Networking 7 08-10-2012 01:33 PM
Do you understand how autotools works? hydraMax Programming 16 03-20-2012 05:19 PM
mutt and crontab , not working :( frenchn00b Linux - General 11 02-21-2010 11:48 PM
Does anyone understand why the audio works, but will not come through my TV? maestro52 Fedora 1 12-15-2009 07:00 PM
help me understand the difference between cron.daily and crontab -e duderancher Linux - Software 7 10-09-2008 11:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration