HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Script help needed
Operating System - Linux
1829770
Members
3129
Online
109992
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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-24-2007 02:33 PM
05-24-2007 02:33 PM
Script help needed
OK...let me see if I can even explain what I'm trying to do here...
I have a file (file1) that gets generated with a list in it like so..
ABC
DEF
GHI
I have another file (file2) with variables in it like so...
BOB="bob@mail.com"
ABC="$BOB"
I am wanting to write a script to do something like this...
. /file2
while read ENTRY
do
grep "$ENTRY" /tmp/filegenfromanotherscript > /tmp/new
FILE=/tmp/new
LIST=$(cat /tmp/new)
if [[ -s ${FILE} ]]; then
cat < /tmp/mail.msg
Here's my message
$LIST
EOM
(echo "Subject: This is it"
cat /tmp/mail.msg
) | rmail RIGHT HERE IS THE PROBLEM
fi
done < /tmp/file1
What I am wanting to do is this: The ENTRY variable will be the same as list in file1 (ie. ABC, DEF, etc). I want to be able to have the script use the ENTRY variable, find that variable in file2 and then send the email to the appropriate address.
File1 is generated regularly and cannot change. Filegenfromanotherscript is fixed (this is just a file with a listing of things I am grepping information from. This file is generated regularly too)
How can I write this script to accomplish what I am trying to do? Thanks for the help.
I have a file (file1) that gets generated with a list in it like so..
ABC
DEF
GHI
I have another file (file2) with variables in it like so...
BOB="bob@mail.com"
ABC="$BOB"
I am wanting to write a script to do something like this...
. /file2
while read ENTRY
do
grep "$ENTRY" /tmp/filegenfromanotherscript > /tmp/new
FILE=/tmp/new
LIST=$(cat /tmp/new)
if [[ -s ${FILE} ]]; then
cat <
Here's my message
$LIST
EOM
(echo "Subject: This is it"
cat /tmp/mail.msg
) | rmail RIGHT HERE IS THE PROBLEM
fi
done < /tmp/file1
What I am wanting to do is this: The ENTRY variable will be the same as list in file1 (ie. ABC, DEF, etc). I want to be able to have the script use the ENTRY variable, find that variable in file2 and then send the email to the appropriate address.
File1 is generated regularly and cannot change. Filegenfromanotherscript is fixed (this is just a file with a listing of things I am grepping information from. This file is generated regularly too)
How can I write this script to accomplish what I am trying to do? Thanks for the help.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2007 06:54 PM
05-24-2007 06:54 PM
Re: Script help needed
Hmm... you need to expand variables named by other variables, so you're going to need "eval" for that. You may also need the variables of file2 exported, so that sub-shells can read them.
Let me try to re-write your script...
#!/bin/sh
set -a # auto-export all variables after this
. /file2
set +a # stop auto-export
while read ENTRY
do
ADDRESS=$(eval echo \$$ENTRY)
LIST=$(grep "$ENTRY" /tmp/filegenfromanotherscript)
if [ "$LIST" != "" ]; then
cat << EOM | mail -s "This is it" $ADDRESS
Here's my message
$LIST
EOM
fi
done < /tmp/file1
... hmm, I think I got rid of most of those temporary files :-)
MK
Let me try to re-write your script...
#!/bin/sh
set -a # auto-export all variables after this
. /file2
set +a # stop auto-export
while read ENTRY
do
ADDRESS=$(eval echo \$$ENTRY)
LIST=$(grep "$ENTRY" /tmp/filegenfromanotherscript)
if [ "$LIST" != "" ]; then
cat << EOM | mail -s "This is it" $ADDRESS
Here's my message
$LIST
EOM
fi
done < /tmp/file1
... hmm, I think I got rid of most of those temporary files :-)
MK
MK
- Tags:
- eval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2007 03:02 PM
05-29-2007 03:02 PM
Re: Script help needed
I appreciate the help. However, I cannot seem to get your script to work. Any thoughts? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2007 03:47 PM
05-29-2007 03:47 PM
Re: Script help needed
Actually, with a little changing I got it to do what I want. Thank you very much!!! Please repost a reply so I can give you more points. Thanks!!!
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP