1846637 Members
1376 Online
110256 Solutions
New Discussion

Re: Scripting

 
SOLVED
Go to solution
Krishnan Viswanathan
Frequent Advisor

Scripting

I have a script looking at some env variables and sending emails. I have imported some of the variables here to give an idea as below:
================================================
#!/bin/sh

cust="cust1 cust2 cust3"
edi_cust1="mailaddress1.com"
edi_cust2="mailaddress2.com"
edi_cust3="mailaddress3.com"

for i in $cust
do
temp="echo edi_cust_$i"
echo $temp
#echo "" | mailx -s "" $temp --- ??????
done
=============================================

What I need to accomplish is basically send an email to all customers listed. "$temp only returns edi_cust1,edi_cust2,edi_cust3.
What I need is the value to the right side of it i.e the email addresses..
How do I accomplish this after getting $temp

Thanks
Krishnan

6 REPLIES 6
Mark Greene_1
Honored Contributor

Re: Scripting

ditch the scripting of the e-mail addresses and setup an alias. Man aliases for information on how; basically edit /etc/mail/aliases as root and create a new entry with all of the addresses to which you want to send the mail. Be sure to use tabs to delimit the fields, then run "newaliases" when you are done to update sendmail with the new info.

HTH
mark
the future will be a lot like now, only later
Rodney Hills
Honored Contributor

Re: Scripting

To get temp to be what you want use, single back quotes (`) instead of double quotes (").

-- Rod Hills
There be dragons...
Eric Ladner
Trusted Contributor
Solution

Re: Scripting

This will accomplish what you want with the script:

#!/bin/sh

cust="cust1 cust2 cust3"
edi_cust1="mailaddress1.com"
edi_cust2="mailaddress2.com"
edi_cust3="mailaddress3.com"

for i in $cust
do
eval temp=$"edi_$i"
echo $temp
#echo "" | mailx -s "" $temp --- ??????
done

Then just change the mail line to something like:

echo "This is a message" | mailx -s "Subject line" $temp
Rodney Hills
Honored Contributor

Re: Scripting

To do double variable substition, you will need to use the "eval" statement-

example-

cust="cust1"
edi_cust1="user@mail.com"
eval temp=`echo \\${edi_$cust}`

Would set temp to user@mail.com.

Note the two \\ ... These are very important!

-- Rod Hills
There be dragons...
Krishnan Viswanathan
Frequent Advisor

Re: Scripting

Rod,

Even with single quotes I just get the variable only, not the value to the right side.

Present Output : edi_cust1
edi_cust2
edi_cust3

What I need is : mailaddress1.com
mailaddress2.com
mailaddress3.com

Thanks
Krishnan

Krishnan Viswanathan
Frequent Advisor

Re: Scripting

Thank you guys - A++.

The "eval" expression worked !!