Getting Email from script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting Email from script
# 1  
Old 08-24-2010
Getting Email from script

I am running a script from crontab and sending the output to another file. This is the statement in crontab:

Code:
45 23 * * * /dst/nikutst/clarity/lib/DSTRestartTest1.sh >> /dst/nikutst/clarity/logs/RestartTest.log

The script runs fine and sends output to the log file. But I always get a system generated email in unix that reads as follows:
Code:
From: Clarity Test <nikutst@wdc-niku-test-app1.dstsystems.com>
Message-Id: <201008240449.o7O4n2aL006667@wdc-niku-test-app1.dstsystems.com>
To: nikutst@wdc-niku-test-app1.dstsystems.com
Subject: Output from "cron" command
Content-Length: 315

Your "cron" job on wdc-niku-test-app1
/dst/nikutst/clarity/lib/DSTRestartTest1.sh >> /dst/nikutst/clarity/logs/RestartTest.log

produced the following output:

java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b02)
Java HotSpot(TM) Server VM (build 1.5.0_16-b02, mixed mode)

Anyone have any idea why I get this email and how to stop it?

This is a copy of the script:
Code:
#!/usr/bin/ksh
#DST Restart Test Application

HOME=/dst/home/nikutst
export HOME

. $HOME/.profile

EMAIL1="claritytecharch@dstsystems.com"
DATE=`date +%y%m%d`"_"`date +%H%M`
echo "Restarting the Test application for date " $DATE 

cd $DOMAIN_HOME

NUM=`find . -name "Test1.log" -exec grep -il "was shutdown" {} \; | grep -v grep | wc -l`
if [ $NUM -eq 0 ]
  then
     echo "Starting to shutdown Test1."
     ./stopTest1.sh >> Test1.log
  else
     echo "Server Test was already shutdown"
fi

sleep 30
echo "Sleeping for 30 seconds"
NUM=`ps -ef | grep nikutst | grep -v grep | grep -c Xms1536m`
if [ $NUM -gt 0 ]
  then
    echo "Clarity: Test1 environment did not shutdown successfully."
#    mailx -s "Clarity: Test1 environment did not shutdown successfully." $EMAIL1 < /dst/nikutst/bea92/user_projects/domains/Test/emptyemail.txt
  else
    echo "Server Test1 is down"
    cd $NIKU_HOME/logs
    mkdir $NIKU_HOME/logs/old_logs/app_logs/$DATE
    for file in app-niku.*;
      do
        mv $file $NIKU_HOME/logs/old_logs/app_logs/$DATE/$file
		echo $file "has been moved to old_logs/app_logs/$DATE directory"
      done
    cp $WL_DOMAIN/bin/Test1.log $NIKU_HOME/logs/old_logs/app_logs/$DATE/
	cd $NIKU_HOME/logs/old_logs/app_logs
    NUM=`find . -mtime +21 | wc -l`
    if [ $NUM -gt 0 ]
       then
          echo "The following files are over 21 days old and are being removed"
          find . -mtime +21
          find . -mtime +21 | xargs rm -rf
    fi
    cd $DOMAIN_HOME
    ./startTest1.sh
    echo "Starting up server Test1"
    NUM=`find . -name "Test1.log" -exec grep -il BEA-000360 {} \; | grep -v grep | wc -l`
    while [ $NUM -eq "0" ]
      do
        sleep 30
        NUM=`find . -name "Test1.log" -exec grep -il BEA-000360 {} \; | grep -v grep | wc -l`
        echo "Server Test1 is still starting up, trying again in 30 seconds"
      done
    echo "Test environment is up."
fi
echo " "


Last edited by Scott; 08-26-2010 at 08:50 AM.. Reason: Please use code tags
# 2  
Old 08-24-2010
Hi.

Try adding this to the end of your cronjob:

Code:
2> /dev/null

# 3  
Old 08-26-2010
Redirect all the errors to the either the same file (RestartTest.log) ir to empty file /dev/null as already told by scottn above.

Code:
45 23 * * * /dst/nikutst/clarity/lib/DSTRestartTest1.sh >> /dst/nikutst/clarity/logs/RestartTest.log 2>>&1

or

Code:
45 23 * * * /dst/nikutst/clarity/lib/DSTRestartTest1.sh >> /dst/nikutst/clarity/logs/RestartTest.log 2> /dev/null

# 4  
Old 08-26-2010
Thank you

Thank you that worked.

I didn't know you could redirect to two different files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need little script to send out email

Hi Scripters, good day. bash-4.2# df -g /apps/prd Filesystem GB blocks Free %Used Iused %Iused Mounted on /dev/xxx 64.00 4.35 94% 1269284 8% /xxx bash-4.2# I was wondering if there is a script when the usage of the mountpoint above hit 98%, email would be... (3 Replies)
Discussion started by: jaapar
3 Replies

2. Shell Programming and Scripting

Simple Email Script

Hi All, Im completely new to scripting but I was wondering can somebody show me how to write a bash script so that if any file enters a specific directory that an email gets sent? I am running a few backups on a few different machines and rysncing them to a remote device, For each server I... (5 Replies)
Discussion started by: jgalvin
5 Replies

3. Shell Programming and Scripting

Email not being sent from shell script

Hi All, I have prepared the below shell script but no email is being sent from the shell script.Not sure what's wrong here: echo $SHELL /bin/bash . $HOME/.profile . /home/oracle/Oracle_xyz.env export log=/orabin/Oracle/rman_Oracle_arch.out rman target /... (4 Replies)
Discussion started by: a1_win
4 Replies

4. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

5. Shell Programming and Scripting

Caller Script should produce and email from 4 different script within it

Hi I wrote a shell script , which includes one output file which is emailed back to me , when the script runs . Now i want to slip the script into 4 different shell scripts each of which taking the parameter PROD or DEV, and include all the 4 different shell scripts in a caller script. ... (3 Replies)
Discussion started by: rxg
3 Replies

6. Shell Programming and Scripting

Email Attachment Script

Hello, I created the following script but i'm trying to figure out why i keep getting an error. #!/usr/bin/perl -w use strict; use warnings; my $baseDir = '/export/home/omcadmin/bin'; my $attachment = "$baseDir/message.txt"; my $from = 'xxx@xxx.com'; my $to = 'xxx@xxx.com'; my... (10 Replies)
Discussion started by: xmaverick
10 Replies

7. Shell Programming and Scripting

Email through Script

I have a script to sent email when error occur in the process. The scripts use a config file where I dot . ./config.cfg into the environment. However, when I export the message below into the environment and echo $msg, it shows only "THERE" the first word in the sentence. export msg=THERE WERE... (2 Replies)
Discussion started by: rkumar28
2 Replies

8. Programming

email extract script

i want to extract the field from, subject and email body part from an inbox on linux redhat 7.x. prefer perl script or any unix utilities script. please help. :confused: (1 Reply)
Discussion started by: gxiong
1 Replies

9. UNIX for Advanced & Expert Users

route email to a script.

Issue: when i send an email to edi@qgatu001.con-way.com it is supposed to get sent to the deliveryagent es_mime_in so it can get proccessed. ok i got this to happen 1x. Will update over the weekend when i can test to let you know if it works completely. sendmail: 8.12.10. sendmail.mc was... (2 Replies)
Discussion started by: Optimus_P
2 Replies

10. Shell Programming and Scripting

Email alert script

I need to code a script, which will run via cron, every 30 minutes. The script will read a file containing a date&time and number (which represents disk space). The file gets appended to every 30 minutes. Here's a sample of the file: CPU 1:04/25/02 1:00 am:1972554 CPU 1:04/25/02 1:30... (1 Reply)
Discussion started by: moon
1 Replies
Login or Register to Ask a Question