How to change crontab output from console to email?


 
Thread Tools Search this Thread
# 1  
How to change crontab output from console to email?

Hi,

We are currently running AIX 6.1 TL4. There are around 30 ksh scripts that are ran from crontab which if an error occurs or a problem with an ftp unix sends the out of the ksh script which goest to our console via the local user hci which is viewed by the mail command. I've tired adding the MAILTO=Test@email.com varaible to the crontab doing a crontab -e as well as adding the variable MAIL=Test@email.com but neither options seemed to work.

I was able piple a mail command to the end of the cron entry however it only displays my subject. It does the job of notifying of an issue but doesn't contain the actual output shown below when looking at the message via mail commad. That option would work but I want any of these jobs to email us and having to piple a mail for each just doesn't seem efficient.

I'm not for sure if our version of AIX doesn't support the mailto varible or if I'm doing something incorrectly. I'm searched this and googled this topic and have tried those variables as well as setting up an aliase which didn't seem to work as well.

I see in the LOGNAME variabile in the output below has hci but I'm not for sure if that is what is being used as the TO: setting for the emial or if there is a config file somewhere that I can update to set the desired email address. Any help would be appreciated.

Example of crontab entry used for piping email would prefer to just have all the crontab jobs for the user hci send an email out instead of having to pipe a mail to each entry. Also I'm not wanting thsi email address to reiceve emails from the root crontab on the hic usr.
Code:
00,5,10,15,20,25,30,35,40,45,50,55 * * * * setroot; /qdxtest/qdx5.7/integrator/kshlib/SJS_SFTMD_ftp | \
mail -s "test" -r "root" "Test@email.com"

Code:
From root Thu Jan 17 11:15:00 2013
Received: (from root@localhost)
	by hsdvim2b.test.local (AIX6.1/8.13.4/8.11.0) id r0HHF0FP5275882
	for hci; Thu, 17 Jan 2013 11:15:00 -0600
Date: Thu, 17 Jan 2013 11:15:00 -0600
From: root
Message-Id: <201301171715.r0HHF0FP5275882@hsdvim2b.test.local>
To: hci
Subject: Output from cron job setroot; /qdxtest/qdx5.7/integrator/kshlib/SJS_SFTMD_ftp, hci@hsdvim2b, exit status 0

Cron Environment:
 SHELL = /usr/bin/sh
 PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java5/jre/bin:/usr/java5/bin
 CRONDIR=/var/spool/cron/crontabs
 ATDIR=/var/spool/cron/atjobs
 LOGNAME=hci
 HOME=/home/hci

Your "cron" job executed on hsdvim2b on Thu Jan 17 11:15:00 CST 2013
setroot; /qdxtest/qdx5.7/integrator/kshlib/SJS_SFTMD_ftp


produced the following output:

bogusvar 


*****************************************************************
	cron: The previous message is the standard output
	and standard error of one of the cron commands.


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by vbe; 01-17-2013 at 01:46 PM.. Reason: code tags...
# 2  
To do what you want the eays way would be :
Write a script that does what you want, then in your cron file:
Code:
00,5,10,15,20,25,30,35,40,45,50,55 * * * * Yourscript >\
 /whereyouwant_logs/yourscript.log  2>&1

# 3  
Thanks VBE for the quick reply. Just so I'm clear are you saying to write a generic send mail script that would contain the desired outside email adderess then direct the ksh job's out to it? So if ftpscript had an error it's output would be sent to the script I'll create which will send the same output message I see when looking at mail? Sorry for respelling this out I'm far from being a unix admin but am tyring to clean up our system a little bit or rather make it more effiicient. I would the just added the script like so below to each crontab entry?

* * * * * ftpscript >\ emailscript 2>&1

Thanks again for your help.

---------- Post updated at 02:38 PM ---------- Previous update was at 02:25 PM ----------

I'm wondering if something like this could also be done similar to the mail pipe having the mail command read in the output from the script

* * * * * setroot; /qdxtest/qdx5.7/integrator/kshlib/ftpscript < mail -s "subject header" -r fromEmail.com ToEmail.com


or if you would have to write the output to a text file first then have it redirected to the mail command? Either way thank you, got a few new ways to play with now.

* * * * * setroot; /qdxtest/qdx5.7/integrator/kshlib/ftpscript > ftpscript.txt | mail -s "subject header" < ftpscript.txt

---------- Post updated 01-18-13 at 01:48 PM ---------- Previous update was 01-17-13 at 02:38 PM ----------

I setup the redirect like you posted and setup a basic email script to fire of if any of the log files contain any data. So far working as desired.

Thanks again VBE for you help.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Gadgets
Difficulty: Medium
The Western Electric Model 500 telephone uses tone dialing to dial phone numbers.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting email output in single line with out space in email

I have tried below email method and i am getting every thing in single line . i have put echo to provide space, but it is not helping my code ( echo "From: $FROM" echo "To: $MAILTO" echo "CC: $CC" echo "Subject: $SUBJECT" echo "MIME-Version: 1.0" echo 'Content-Type: multipart/mixed;... (6 Replies)
Discussion started by: mirwasim
6 Replies

2. Shell Programming and Scripting

How to change banner message for console login?

Hi All, Whenever I login to server via console, after providing username (root) it displays a banner message. I want to remove this message Serverabc : root Welcome to Server !!! Password: It is Centos 5.4 box. I have checked /etc/issue and /etc/motd. It does not... (8 Replies)
Discussion started by: kalpeer
8 Replies

3. Solaris

No Console Output

Hey everyone I have a sparc enterprise T2000 I'm trying to install solaris 10 on. The only way I can connect to it is the SER MGT console, but I'm not getting anything to display (in Hyper terminal, or PUTTY) when I boot it. Upon googleing, all I get back is "No output may have been generated.... (4 Replies)
Discussion started by: goodvikings
4 Replies

4. Shell Programming and Scripting

Crontab issue: getting email but with out body

I have a oracle sh script test.sh #!/bin/bash R=`sqlplus -S *****/*********@dfsdf <<ENDOFSQL set serveroutput on size unlimited; execute DBMS_SNAPSHOT.REFRESH( '"MIS_ADMIN"."MV_SURVEY_UNITS_CENSUS"','F'); execute DBMS_SNAPSHOT.REFRESH( '"MIS_ADMIN"."MV_SURVEY_UNITS_CENSUS_PART"','F');... (1 Reply)
Discussion started by: ramkia6
1 Replies

5. UNIX for Dummies Questions & Answers

How to change the window size of Linux console in VMware?

The console's window size in VMware is too small. How can I change it? I mean changing the window size of pseudo terminals such as tty1, not the kde desktop. I think it may be connected to resolution.But changing resolution in the menu.lst of grub doesn't work. Any ideas? Thanks. (4 Replies)
Discussion started by: vic005
4 Replies

6. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

7. Solaris

Crontab email issue

Hi, I have a script that sends a db extract file as an email attachment. I have a crontab created to run it everyday at 8 am.. 00 08 * * * ksh /home/rtaaa/tbasd/report.sh > /home/rtaaa/tbasd/logs/report.log When i just run the "ksh /home/rtaaa/tbasd/report.sh >... (5 Replies)
Discussion started by: ryannam
5 Replies

8. Shell Programming and Scripting

Crontab change and email notification

Hey guys Just need some help with crontab.Iam looking for a script that will alert particular user about its change through sendmail.We are using bash here. --CoolKid (3 Replies)
Discussion started by: coolkid
3 Replies

9. UNIX for Dummies Questions & Answers

console message from Crontab run

I run my nightly backup thru a crontab job. Is there any way to get the message to mount a new tape to the console? Currently it appears to go to an email. (1 Reply)
Discussion started by: aixhelp
1 Replies

10. UNIX for Dummies Questions & Answers

Change Console Title

Hello. I am trying to figure out how to change the title of my console window. I don't need it to dynamically change with my current directory. I just want to be able to change the name of it, so when I minimize the window I can see which windows are for what purpose. I've tried using the... (8 Replies)
Discussion started by: medmonson
8 Replies

Featured Tech Videos