Solved

Finding out if "mail" function is availabe

Posted on 2015-01-11
14
133 Views
Last Modified: 2015-01-14
How do i know if the "mail" funcion in unix is avialbe in some directory??

I have some script in a machine using mail function, when i execute it in machine1 i get the mail sent

however when i execute the same script in machine2 i dont get any error, however no mail is being sent....

how can i know if the mail function is actually enable or availabe in that machine/location???
0
Comment
Question by:celtician
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40543679
which mail
0
 

Author Comment

by:celtician
ID: 40543688
I get this when executing that:

machine:username:/home/username/data$ which mail
/usr/bin/mail
0
 
LVL 84

Expert Comment

by:ozo
ID: 40543690
Then the "mail" function is available in /usr/bin
0
 

Author Comment

by:celtician
ID: 40543692
so, if i want to execute it from another location such as /usr/data/myscript.ksh, what do i need to do? do i need to declare it somehow in the script??
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40543693
If the script on machine1 is sending thru a user that exists on machine1, the same user may not exist on machine2.  You may have to change the user that is sending the email on machine2.
0
 

Author Comment

by:celtician
ID: 40543694
in this case i would like to send directly from machine2, not making the call from machine1
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40543699
Can you post your script that sends the email, at least that part of the script?  You can hide or obscure the email address you are using.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:celtician
ID: 40543701
sure, it works perfectly on machine1, but not on machine2

#!/bin/ksh

MAIL_FILE="testfile.txt"

rm -f $MAIL_FILE



echo "From:ScriptTesol" > $MAIL_FILE
echo "To:Me LastName <mail@mycompany.com>" >> $MAIL_FILE
echo "Subject:Test eMail" >> $MAIL_FILE
echo "Content-Type: text/html" >> $MAIL_FILE
echo "<html>" >> $MAIL_FILE
echo "<body style='font-family:calibri;font-size:14px;'>" >> $MAIL_FILE
echo "<h2> Test email h2 </h2>" >> $MAIL_FILE


cat $MAIL_FILE|mail me@mycompany.com
0
 
LVL 84

Expert Comment

by:ozo
ID: 40543704
does
mail -v me@mycompany.com
report anything?
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
ID: 40543705
You can always add the directories or folders that contain your commands files in PATH env variable, for example:

PATH=$PATH:/usr/bin ; export PATH

This will take care of it, or you can directly call the file by using its full path name in the script:

/usr/bin/mail
0
 

Author Comment

by:celtician
ID: 40543709
Whe doing mail -v me@mycompany.com i get:


mail: illegal option -- v
mail: Usage: [-ehpPqr] [-f file] [-x debuglevel]
or      [-tw] [-m message_type] [-T file] [-x debuglevel] persons
or      [-x debuglevel]
0
 
LVL 84

Expert Comment

by:ozo
ID: 40543712
I don't see me@mycompany.com as one of the options
what does
man mail
say?
0
 

Author Comment

by:celtician
ID: 40543720
In the funcion above the mail is being sent using that function and being set as parameter as its written.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40543726
I substituted 'sendmail' for 'mail'. Your script works perfectly sending to one email address and not at all sending to another one.  The mail server you are sending to or thru may make a difference also.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now