- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script problems attributing variables
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2001 10:49 AM
05-23-2001 10:49 AM
I?m making a script to send several emails and the addresses are defined as variables. The problem is that I?m trying to use a single line for the email part but it?s not working. This part of the script is like this:
export NUM=3 #number of email addresses
export EMAIL1=test1@test.com
export EMAIL2=test2@test.com
export EMAIL3=test3@test.com
while [ $NUM -ne 0 ]
do
EMAIL="EMAIL$NUM"
echo test | mailx -s"test subject" $EMAIL
let "NUM = NUM - 1"
done
The $EMAIL shows EMAIL1, EMAIL2 and EMAIL3 but I wanted it to assume the real email addresses.
I asked a friend who works with java script and he told me to use arrays. Do we have that for shell scripting ??
Does anybody now how to do it in any way ??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2001 10:58 AM
05-23-2001 10:58 AM
Re: Script problems attributing variables
Would an alias work as well, or do you need to have some sort of conditional logic to determine which addresses to send to?
If the list is static, then there'd be no need to invent fancy variables.
Alternatively, would it work as well to employ a case statement in place of your do/done?
Just a thought.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2001 11:18 AM
05-23-2001 11:18 AM
Re: Script problems attributing variables
The email list is static and I don?t need to use any logic to determine the addresses. Actually it shold be very simple but I don?t know how to do it.
Can you send me some example using alias ? It could help a lot once I don?t know how to use it.
Tks,
Guilherme Belinelo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2001 11:21 AM
05-23-2001 11:21 AM
SolutionI took your script and modified it to use an array. Here is what it looks like:
#!/bin/sh
export NUM=3 #number of email addresses
export EMAIL[1]=test1@test.com
export EMAIL[2]=test2@test.com
export EMAIL[3]=test3@test.com
while [ $NUM -ne 0 ]
do
EMAIL="EMAIL$NUM"
#echo test | mailx -s"test subject" $EMAIL
echo "EMAIL[$NUM] = ${EMAIL[$NUM]}"
let "NUM = NUM - 1"
done
I remarked out the line that does the 'mailx', just for testing purposes, and I put in a line to echo the value of the EMAIL array variable. When I run it, here is the output:
EMAIL[3] = test3@test.com
EMAIL[2] = test2@test.com
EMAIL[1] = test1@test.com
Does this help? Also, for the 'mailx' command you can specify the e-mail addresses separated by commas. This means you can create one variable with all the addresses in it and use it something like this:
EMAIL="test1@test.com, test2@test.com, test3@test.com"
echo test | mailx -s"Test subject" $EMAIL
I hope that helps.
Good luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2001 11:22 AM
05-23-2001 11:22 AM
Re: Script problems attributing variables
cat emaillist | xargs -n1 mailx -s "mysubject"
This would run mailx for each line in emaillist, appending the line on the end of the mailx command.