sendEmail: Script and Array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sendEmail: Script and Array
# 1  
Old 04-21-2012
sendEmail: Script and Array

I have a script that send email using sendEmail (CentOS shell)
script is:

Code:
sendEmail -vvv -u "TestCompany, Inc.: USB Added" -f user@domain.com -t To@domain.com -s ASPMX.L.GOOGLE.com -m "USB Activity" -o tls=aut
o username=user3@domain.com password=password

So far this works fine.

Now i create a ConfigFile as follows:
Code:
Company=TestCompany, Inc.
FromEmail=user@domain.com
Password=password
ToEmail=To@domain.com
Smtp=ASPMX.L.GOOGLE.com

and Now I modify my script as follow:

Code:
#!/bin/sh
i=1;
while IFS="=" read VAR VALUE
do
        VAR="${VAR// }"
        Values[$i]=${VALUE}
        let i++;
done <  ConfigFile

Code:
sendEmail -vvv -u "${Values[1]}: USB Added" -f ${Values[2]} -t ${Values[4]} -s ${Values[5]} -m "Test Email" -o tls=auto username=${Values[2
]} password=${Values[3]}

I get following error:
Code:
'25 failed: IO::Socket::INET: Bad hostname 'ASPMX.L.GOOGLE.comempt to ASPMX.L.GOOGLE.com
Apr 21 12:11:35 box2 sendEmail[26378]: HINT => Try specifying a different mail relay with the -s option.

Now I'm unable to understand that why I'm getting this error. even when i try to echo Values it shows me correct values. Also when i run same command from command prompt it sends email...then where I'm doing wrong.? Please help. thanks.
# 2  
Old 04-22-2012
Personally, I'd quote the string "TestCompany, Inc." in ConfigFile

HTH
# 3  
Old 04-22-2012
There should be double quotes around the variable references..
Also, a command cannot be spread over two lines like that.

I do not think the quotes in the config file are necessary, since with
Code:
while IFS="=" read VAR VALUE

$VALUE sweeps up everything to the right of the =-sign

There are a couple of questions I would have are, like why are the values being put in a numbered array, why is a loop being used, why do spaces need to be removed from $VAR and what is the benefit of creating a config file format like that, in which only the information needed for a single email can be stored.

--
As a side note: the specified shell on line 1 does not match the syntax in the script, which is bash or ksh93. CentOS shell is not the name of a shell.
# 4  
Old 04-22-2012
1. I also tried using "". but I got same issue.
2. Command is not spread over 2 line. in CentOS it is just one line.
3. I tried using without array, loop and values (as given below) but again no success.
Code:
. ConfigFile
sendEmail -vvv -u "$Company: USB Added" -f "$FromEmail" -t "$ToEmail" -s "$Smtp" -m "Test Email" -o tls=auto username="$FromEmail" password="$Password"

4. I also tried bash but same result.
5. Config file is created as this program will be used by different resources so every1 can adjust parameters without opening source file. Also there are other tasks too that are using config file so one place is better for this kind of information.
# 5  
Old 04-22-2012
If you source it then indeed you need to make sure that space and special characters are protected from the shell like Habitual suggested:
Code:
Company="TestCompany, Inc."

# 6  
Old 04-22-2012
@Scrutinizer: Tried "" when sourcing file but no success.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sendemail how to send an email with a subject variable

Hi,:) I try this : #!/bin/bash sender="me@example.com" recipient="you@example.com" subject="TEST FILE" server="0.0.0.0" file=$(cat file.txt) /usr/bin/sendemail -f $sender -t $recipient -u $subject -m $file My file.txt: BLABLALA BLABLABLA (7 Replies)
Discussion started by: Arnaudh78
7 Replies

2. Shell Programming and Scripting

SendEmail and Variable

Hi everyone, I try to send an email with "sendemail", I created four variables for do cleaner but it doesn't work :( below : #!/bin/bash sender=$(X@x.com) recipient=$(x@x.com) subject=$(Files Copy) server=$(x.x.x.x) /usr/bin/sendemail -f $sender -t $recipient -u $subject -m blablabla... (2 Replies)
Discussion started by: Arnaudh78
2 Replies

3. UNIX for Dummies Questions & Answers

Sendemail Error - Authentication... failed

SCO Unix OpenServer v6. We use the script below for sending mass emails with attachments. sendemail -f $From_user -o message-file=/u/fg4/data/EmailDefaultBody.html -u $su bj -s $MAIL_SRVR -xu $MAIL_USER -xp $MAIL_PSWD -a $emlname.pdf -t $MAILTO MAIL_SVR=SMPTOUT.SECURESERVER.NET ... (0 Replies)
Discussion started by: jet47
0 Replies

4. Solaris

Send multi content email using sendemail utility

Hi Guys, I am trying to send email from solaris server using sendemail utility. I want to send multi content email. For example, i want to send email body with html file and a attachment of txt file. I using below code but the html not render correctly in email body. ( echo "To:... (2 Replies)
Discussion started by: tharmendran
2 Replies

5. Ubuntu

Sendemail... is there a receivemail?

Hello, I installed the sendemail program for commandline/script outgoing mail. It works great. I was wondering if there is some simple program to receive mail. Something like the sendemail program... Grtz (5 Replies)
Discussion started by: raylier
5 Replies

6. UNIX for Advanced & Expert Users

Help in perl script Array.

hi Team, i need a help in perl , i need to get values(10 rows +) from perl GUI and insert those values into oracle table. am trying to achive this in Perl array, can you please help me on this. thanks senthil (1 Reply)
Discussion started by: senkerth
1 Replies

7. Shell Programming and Scripting

SendEmail - Script reading database file with sleep command

Hello, I would like to send email message to my mail list. I have been running linux based server and I submitted this process manually up to now. I would like to send each individual with a shell script. In ssh panel, I tested below command and it works smoothly. sendEmail -t... (1 Reply)
Discussion started by: baris35
1 Replies

8. Solaris

Solaris 10 Sendemail with Attachment

Hello I need your kind help for configuring email on Solaris 10 so I can send reports from the system to my management and my colleagues. I have the IP address of the email server of my company and the port 2525. I went through many documents online with no luck. Can any one help me... (4 Replies)
Discussion started by: samer.odeh
4 Replies

9. Shell Programming and Scripting

Using array in script?

Dear all, I have following set of code which I want to modify In the given code, the given PATH535 only accept the single path. I would like to modify it to make it array and should be able to pass several of the path address together. for example like following: PATH535=/pathA/log/A/... (5 Replies)
Discussion started by: emily
5 Replies
Login or Register to Ask a Question