Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-12-2012
Registered User
 
Join Date: Jun 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Sending Mail via shell script

I am in need of a script that will send out emails while going through a NAT. What I have that works is as follows:

Code:
display_remote_IP | sort | uniq | while read i
do
        FOUND=0
        for IP in `echo $ACCEPTABLEIP`
        do
                if [ "$i" == "$IP" ]; then
                        FOUND=1
                        continue
                fi
        done
        if [ $FOUND -eq 0 ]; then
                echo "IP address $i NOT in acceptable IP list to access server  ......  sending email"
                echo "IP Address $i NOT in acceptable IP list to access server, please investigate" | mail -s "Unauthorized Connection To My_Server Alert" someone@mail.com
        fi
done

Now I have to run this in an environment where the mail server is not in DNS. I therefore have to go through a NAT, 100.100.100.100

How do I add that to my script so that it goes through the IP to send the email?
Moderator's Comments:
code tags please

Last edited by jim mcnamara; 06-12-2012 at 04:24 PM..
Sponsored Links
    #2  
Old 06-13-2012
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 3,301
Thanks: 27
Thanked 456 Times in 355 Posts
Quote:
Originally Posted by ldapguy View Post
How do I add that to my script so that it goes through the IP to send the email?
Short answer: you shouldn't.

Long version: it is simply not the task of a script to "know how to deliver mails". This should be the knowledge of the mailing daemon and be configured there. "mail" (which you use in your script) is a client program which acts as a frontend to this delivery system: it takes a mail message with all relevant information (addressee, content, subject line, etc.) and passes this to a daemon (sendmail, whatever), which should deliver this to an MTA (mail transfer agent) or to the addressees systems mail service directly. In any case your script should not be concerned with how mail gets there.

To use an analogy: if you want to use any other IP service (say, FTP) in your script, it shouldn't be concerned in dealing with IP routing or something such either - this would be the job of routers, so let them do it.

Bottom line: configure your "sendmail" or whatever you use to send mails properly and leave your perfectly written script alone.

I hope this helps.

bakunin
Sponsored Links
    #3  
Old 06-13-2012
Registered User
 
Join Date: Jun 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks bakunin for the response. That makes a lot of sense now. I got the server guys to check that out and you were right, sendmail was not configured correctly in that environment.

Appreciate your help!!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sending mail from shell script prarat Shell Programming and Scripting 6 06-04-2012 06:56 AM
shell script not sending mail Pandee Shell Programming and Scripting 5 04-26-2012 03:01 AM
Shell script for creating log file and sending mail? san_dy123 Shell Programming and Scripting 4 02-29-2012 05:01 AM
Shell script for sending automatic email to personal mail id rrd1986 Shell Programming and Scripting 4 01-19-2010 12:53 PM
sending a mail using shell script anitha126 Shell Programming and Scripting 1 11-27-2008 06:31 AM



All times are GMT -4. The time now is 08:05 PM.