Sponsored Content
Top Forums Shell Programming and Scripting Multiple emails via telnet in a script Post 302462232 by DGPickett on Wednesday 13th of October 2010 03:32:18 PM
Old 10-13-2010
One per:
Code:
For a in $ADDRESSES
do
  echo "rcpt to:$a" 
  sleep 10 
done

This goes faster if:
  • you use 'expect'/'autoexpect', but it is a bit of a project to use it dynamically if you are not a tk/tcl guru yet, or
  • do your own 'expect': send the telnet output to a flat file and grep for responses in it every second or even less ( I wrote a 'nap' command in trivial C to sleep in milliseconds using poll(0,0,#) ). Of course, for n recipients, you need n+m 'grep -c' responses.

Here is one I wrote when the local mailx did not deliver:

Code:
$ cat mysrc/mailx4            
#!/usr/bin/ksh

waitpat_e(){

        export zt=0

        if [ "$2" = "" ]
        then
                export zc=2
        else
                export zc=$2
        fi

        while (( $(tail -$zc </tmp/dpmail.$$|egrep -c "$1") < 1 ))
        do
                if (( $(fgrep -c 'Connection closed by foreign host.' </tmp/dpmail.$$) > 0 ))
                then
                        exit
                fi

                zt=$(( $zt + 50 ))

                if (( $zt > 10000 ))
                then
                        return 1
                fi

                napx 50

                if [ ! -f /tmp/dpmail.$$ ]
                then
                        return 2
                fi
        done

        return 0
}

waitpat(){

        export zt=0

        if [ "$2" = "" ]
        then
                export zc=1
        else
                export zc=$2
        fi

        while (( $(egrep -c "$1" </tmp/dpmail.$$) < $zc ))
        do
                if (( $(fgrep -c 'Connection closed by foreign host.' </tmp/dpmail.$$) > 0 ))
                then
                        exit
                fi

                zt=$(( $zt + 50 ))

                if (( $zt > 10000 ))
                then
                        return 1
                fi

                napx 50

                if [ ! -f /tmp/dpmail.$$ ]
                then
                        return 2
                fi
        done

        return 0
}

cd

. ./.profile

while [ $# != 0 ]
do
if [ "$1" = "-s" ]
then
  export zsub="$2"
  shift
  shift
  continue
fi
if [ "$1" = "-r" ]
then
  export zsndr="$2"
  shift
  shift
  continue
fi
zrec="$zrec $1"
shift
done

if [ "$zsub" = "" ]
then
  export zsub="From idxx(real_idxx)@hostxxx, no subject"
fi

if [ "$zrec" = "" ]
then
  zrec="David.Pickett@xxx.com"
fi

if [ "$zsndr" = "" ]
then
  export zsndr="David.Pickett@xxx.com"
fi

>/tmp/dpmail.$$

(
waitpat '^220 '
echo "HELO"
waitpat '^250 '
echo "Mail From: $zsndr"
waitpat '^250 ' 2
export zct=3
for r in $zrec
do
 echo "Rcpt To: $r"
 waitpat '^250 ' $zct
 zct=$(( $zct + 1 ))
 zrecs="$zrecs ; $r"
done
"cho "Data
waitpat '^354 '
echo "From: $zsndr
To:${zrecs#*;}
Subject: $zsub
"
*\)$/. \1/'\(
echo "
."
waitpat_e '^250 '
echo "quit"
)|tcpipe -8E mail_host_ip_or_name 25 >/tmp/dpmail.$$ 2>&1

mv -f /tmp/dpmail.$$ /tmp/mailx4_last

$


Last edited by DGPickett; 10-14-2010 at 12:48 PM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

uuencode mailx - send multiple emails

The following is an extract from one of my Shell Scripts which uses uuencode and mailx to send an email with multiple attachements: uuencode $LOG_REPORT $(basename $LOG_REPORT) uuencode $HTML_FILE $(basename $HTML_FILE ) ) | if then mailx -b "$COPY_TO" -s "$SUBJECT" -r "$MAIL_FROM"... (2 Replies)
Discussion started by: suthera
2 Replies

2. Programming

Sending emails in C program for multiple machines on Linux/OSX

Hey guys, i am creating a tool that'll run a couple network test, generate a report then email the report. Now i a bit stuck with the email sending part... I tried at first a script which worked on some machines but then it'll work fine on some machine and act up on others... I can't really rely... (2 Replies)
Discussion started by: Jess83
2 Replies

3. Shell Programming and Scripting

mailx script to do multiple emails

I am looking for a script that I can use with mailx to do the following: 1. Grab usernames from a flat file (one at a time) 2. Attach a file to the email and mail out. Thanks. Cubefeed (3 Replies)
Discussion started by: CubeFeed
3 Replies

4. Shell Programming and Scripting

PHP Mail Script Takes Hours to Send emails

guys, i have a php script that i wrote that takes hours to send emails to recipients. i can't post the content of this script in here because the script contains some very important confidential information. so my question is, why is it that when the php script runs, it runs successfully, but... (3 Replies)
Discussion started by: SkySmart
3 Replies

5. UNIX for Dummies Questions & Answers

Export emails into spreadsheet (script)

I 'd like to export emails from my mail client(mac) inbox into an Excel spreadsheet. I need the Subject, From fields, Return-Path and the Message-ID. Does anyone know how I can do this? Thanks, Newbie :) (1 Reply)
Discussion started by: Cris
1 Replies

6. Red Hat

Postfix: emails addressed to multiple smart hosts

Hi, I am in process of setting up a SMTP server on RHEL 6 using Postfix. I am stuck at one point so any help would be appreciated. I have configured my xsender to use this new SMTP server as its mail server. If I send any emails addressed TO example.com the SMTP server should use the... (0 Replies)
Discussion started by: max29583
0 Replies

7. Shell Programming and Scripting

Avoid multiple emails being sent - Counter, Loop?

Hello, I have currently coded a bash script below in which it does the following: # Archives compressed file from another location. Basically it moves *.gz files to another location. The script also sends an email whenever a new compressed file is placed. This is the issue that i... (5 Replies)
Discussion started by: Wizard_1979
5 Replies

8. Shell Programming and Scripting

Need shell script to Telnet multiple node , Ping some IP and print output

Hi Team, Need shell script to Telnet multiple node , Ping some IP and print output like pass or fail. Need this script to check reachability of multiple nodes at same time. Help me. I use this but not working... Eg. in this script i need to telnet... (4 Replies)
Discussion started by: Ganesh Mankar
4 Replies

9. Shell Programming and Scripting

Sending files to multiple emails

Hi All, I want to send each file to each email id as below. Instead of writing saparate 10 mail commands can we do it in a simple step. file1.csv to raghu.s@hps.com file2.csv to kiran.m@hps.com file3.csv to kenni.d@hps.com file4.csv to rani.d@hps.com file5.csv to sandya.s@hps.com... (2 Replies)
Discussion started by: ROCK_PLSQL
2 Replies
All times are GMT -4. The time now is 02:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy