05-15-2008
Mail command in UNIX
1)My main script Calls a function IsDomain to check whether the domain is valid or not
PROD>/appl/retek/mpscripts/cat mg3TRn01
#!/bin/ksh
#
# Standard Header Files
#
#
. ${0%${0##*/}}UKMPFunctionLibrary.test
#
# START
#
ScriptStart
#
# Check that domain exists.Print & Commit the ASAP queue
#
IsDomain $SPDOM
ScriptEnd
#
# END
#
2) My global function library UKMPFunctionLibrary.test has the below functions defined
#
# Set Schedular Envronment Variables
#
. ${0%${0##*/}}UKMPEnv
THISFILE=${0##*/}
OVWFILE=$LOGS/mps_ovw.log
LOGFILE=$LOGS/$THISFILE.log.$(date "+%y%m%d%H%M%S")
TMPFILE=$TEMP/$THISFILE.tmp
WARNINGS=false
#
# Standrad log function
#
Log() {
case $2 in
0) LOGMSG=INFO;;
1) LOGMSG=WARNING;WARNINGS=true;;
2) LOGMSG=ERROR;;
*) echo $1 >>$LOGFILE; return;;
esac
echo $(date +"%T")' - '$LOGMSG' - '$1>>$LOGFILE;
echo $THISFILE' - '$(date +"%T")' - '$LOGMSG' - '$1
>>$OVWFILE
}
#
# Standard Mailing {Parameters 1 - Subject 2 - List of mail ids}
#
SendMail()
{
if [ $# -eq 2 ];then
echo " "|mail -s "$1" "$2";return $?
elif [ $# -eq 3 ];then
cat $3|mail -s "$1" "$2";return $?
else
return 2
fi
}
#
# Exit Codes {0 - Success; 1 - Warning; 2 - Failure}
#
Exit() {
case $1 in
0) Log 'END - SUCCESS' 0;exit 0;;
1) Log 'END - SUCCESS WITH WARNINGS' 1;exit 1;;
2) Log 'END - FAIL' 2;
MAILLIST="shilpi.sood@in.tesco.com";
SUBJECT="ALERT - The job $THISFILE has failed @
$(date)!Please Check";
SendMail "$SUBJECT" "$MAILLIST";
exit 2;;
*) Log 'END - ERROR' 2;exit 2;;
esac
}
#
# Standard Log File Heading
#
ScriptStart() {
echo $(date +"%Y%b%d")>>$OVWFILE
echo $(date +"%Y%b%d")>$LOGFILE
Log "START" 0
}
#
# Standard Log File End
#
ScriptEnd() {
Log 'END' 0
if [ $WARNINGS == 'true' ];then
Log 'SUCCESS WITH WARNING' 0;exit 0
else
Log 'SUCCESS' 0;exit 0
fi
}
#
# To check the existance of a domain {Parameter 1 - Domain
# Path}
#
IsDomain() {
checkDomain -d $1 -type simple>>$LOGFILE
if [ $? -ne 0 ];then
Log "Domain $1 does not exist" 2;Exit 2
fi
}
3) On failure the script is not returning the correct return code due to which we are facing issues.
In the global function Exit() can we not call the global function Sendmail()?
How can I edit the code so that the correct return code is passed from the script on failure?
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi
Is there any way to use UNIX and Perl to automate sending e-mail. I got a dynamic changing file that send out to people in my mailing list and want to experinment to see if Perl and UNIX can send it out for me when the content is change. I found a Perl source code but dont really know how to... (4 Replies)
Discussion started by: jy2728
4 Replies
2. UNIX for Dummies Questions & Answers
hi,
Im trying to send a e-mail to two people e.g X & Y . I run a shell script that uses the mail command to send an email to both these people . The email that i am sending contains two attatchments that i 'add' to a .mail file.
mail <recipients> < filename.mail
The problem that im... (1 Reply)
Discussion started by: nbvcxzdz
1 Replies
3. UNIX for Dummies Questions & Answers
Hello,
When i am using mail command like this:
mail -r prashant.aggarwal@xx.com -s "hiiii" prashant.aggarwal@xx.com < Content.txt i am abl eto dend a mail. Content.txt is a file from which contents are being reda
But when i am trying to execute it thru a shell scipt like this it's giving ... (3 Replies)
Discussion started by: cprash.aggarwal
3 Replies
4. Shell Programming and Scripting
well, I have a script with this code inside:
nohup /usr/sbin/auditstream | /usr/sbin/auditselect -m -e "event== USER_Create || event== USER_Remove || event== USER_Change || event== GROUP_Create || event== GROUP_Remove || event== GROUP_Change || event== PASSWORD_Change " | /usr/sbin/auditpr -h... (4 Replies)
Discussion started by: iga3725
4 Replies
5. UNIX for Dummies Questions & Answers
Hi all ,
I wanted to know how does a 'mail' command works in unix. Does it use an smtp server internally ?
How and where it is configured then ? I am trying to google out the same , but not getting much help.
Any suggestions with be of great help.
- Andy (5 Replies)
Discussion started by: anindyabecs
5 Replies
6. UNIX for Dummies Questions & Answers
I recently generated myself the following error when attempting to use the Unix mail command:
The flags you gave make no sense since you're not sending mail.
There is a recent thread about this issue here in unix.com (with a title very much like this thread's title), but it was closed... (2 Replies)
Discussion started by: Clovis_Sangrail
2 Replies
7. Shell Programming and Scripting
Hi All,
Is it possible to email a file from another directory in Unix shell prompt? In other words, do we have to be in the directory where the file is located to mail the file?
I was in the Mail directory and my file (filename) is in the Practice directory. I tried this and it didn't work:... (7 Replies)
Discussion started by: onlinelearner02
7 Replies
8. UNIX for Advanced & Expert Users
Hi all,
I want to send a mail for my business needs from outlook account to an unix server (HP-UX) but I don't send any mail. While I can send from the unix server to my outlook account, I can't send from outlook to unix.
How can I achieve this ? How can I send a mail from my outlook or other... (2 Replies)
Discussion started by: igelegin
2 Replies
9. UNIX for Dummies Questions & Answers
Hi All,
In my .ksh script, I am sending an email with body and attachment (.txt) using sendmail command. I am able to receive the attachement along with the body of the mail. But I am getting special characters along with the content in the .txt. Also the alignment is incorrect. Can you please... (7 Replies)
Discussion started by: KRR
7 Replies
10. Shell Programming and Scripting
I am using HP-UX server. I tried to send the email with attachment, I used the below unix command to send with attachment but it doent work.
uuencode pepsitoday.csv | mailx -s "csv file" ramkumar15@pepsi.com
---------- Post updated at 02:10 AM ---------- Previous update was at... (2 Replies)
Discussion started by: ramkumar15
2 Replies
LEARN ABOUT DEBIAN
log::any::test
Log::Any::Test(3pm) User Contributed Perl Documentation Log::Any::Test(3pm)
NAME
Log::Any::Test -- Test what you're logging with Log::Any
SYNOPSIS
use Test::More;
use Log::Any::Test; # should appear before 'use Log::Any'!
use Log::Any qw($log);
# ...
# call something that logs using Log::Any
# ...
# now test to make sure you logged the right things
$log->contains_ok(qr/good log message/, "good message was logged");
$log->does_not_contain_ok(qr/unexpected log message/, "unexpected message was not logged");
$log->empty_ok("no more logs");
# or
my $msgs = $log->msgs;
cmp_deeply($msgs, [{message => 'msg1', level => 'debug'}, ...]);
DESCRIPTION
"Log::Any::Test" is a simple module that allows you to test what has been logged with Log::Any. Most of its API and implementation have
been taken from Log::Any::Dispatch.
Using "Log::Any::Test" sends all subsequent Log::Any log messages to a single global in-memory buffer. It should be used before Log::Any.
METHODS
The test_name is optional in the *_ok methods; a reasonable default will be provided.
msgs ()
Returns the current contents of the global log buffer as an array reference, where each element is a hash containing a category, level,
and message key. e.g.
{
category => 'Foo',
level => 'error',
message => 'this is an error'
},
{
category => 'Bar::Baz',
level => 'debug',
message => 'this is a debug'
}
contains_ok ($regex[, $test_name])
Tests that a message in the log buffer matches $regex. On success, the message is removed from the log buffer (but any other matches
are left untouched).
does_not_contain_ok ($regex[, $test_name])
Tests that no message in the log buffer matches $regex.
empty_ok ([$test_name])
Tests that there is no log buffer left. On failure, the log buffer is cleared to limit further cascading failures.
contains_only_ok ($regex[, $test_name])
Tests that there is a single message in the log buffer and it matches $regex. On success, the message is removed.
clear ()
Clears the log buffer.
SEE ALSO
Log::Any, Test::Log::Dispatch
AUTHOR
Jonathan Swartz
COPYRIGHT & LICENSE
Copyright (C) 2009 Jonathan Swartz, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl v5.10.1 2009-12-08 Log::Any::Test(3pm)