- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell script - while do loop
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
Discussions
Discussions
Discussions
Forums
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
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
тАО09-26-2002 02:04 AM
тАО09-26-2002 02:04 AM
I want to use a while loop to read from a file. I would have a file called "notify", which would contain a list of users for who I want to email, there would be one email address per line. For example in the "notify" file I could have:
chuck@dom.com
dennis@dom.com
and so on
Then, for each person in the file I want to do awk out the username before the @ symbol:
while there are people in the file
echo "name, database is going down" | mail emailaddy
end
So, in effect for the first execution of the loop this would happen:
echo "chuck, database is going down" | mail chuck@dom.com
Regards
Chuck
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2002 02:27 AM
тАО09-26-2002 02:27 AM
Re: Shell script - while do loop
while read addr ; do
echo $addr | cut -d@ -f1 | read name
echo "$name, database is going down | mail $addr"
done < notify
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2002 02:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2002 04:36 AM
тАО09-26-2002 04:36 AM
Re: Shell script - while do loop
while read addr ; do
echo "${addr%@*}, database is going down" | mail $addr
done < /tmp/names
the ${} is a ksh construct. The %@* will remove the pattern that starts with @ from the variable.
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2002 04:43 AM
тАО09-26-2002 04:43 AM
Re: Shell script - while do loop
The built-in pattern substitution command offerd by Tom is available in the Posix shell too. See 'man -sh-posix'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2002 05:01 AM
тАО09-26-2002 05:01 AM
Re: Shell script - while do loop
while read a b
do
echo "$a database is going down" |mail $a\@$b
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2002 05:04 AM
тАО09-26-2002 05:04 AM
Re: Shell script - while do loop
cat dbusernotifyfile | awk -F\@ '{name=$1; email=$0; printf("echo %s, database is go
ing down \| mailx -s \\\"database is going down\\\" %s\n", name, email);}' | xargs
-i sh {}
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2002 05:42 AM
тАО09-26-2002 05:42 AM
Re: Shell script - while do loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2002 05:44 AM
тАО09-26-2002 05:44 AM
Re: Shell script - while do loop
James & Harry, your commands don't work!?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2002 05:48 AM
тАО09-26-2002 05:48 AM
Re: Shell script - while do loop
#!/usr/bin/sh
addr=jrferguson@xyz.com
echo ${addr#*@} #...yields xyz.com
echo ${addr%@*} #...yields jrferguson
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2002 05:57 AM
тАО09-26-2002 05:57 AM
Re: Shell script - while do loop
If you CUT & PASTED then you might have eneded up with a CTRL-J in the middle of the line. I just cut and pasted and I had to remove the CTRL-J and it worked fine.
I included the subject line, because there is nothing more anoying than an email without a subject, which is why I used mailx.
what was the error message? Did you replace the file being cat'ed with the file of email addresses you are using?
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2002 06:34 AM
тАО09-26-2002 06:34 AM
Re: Shell script - while do loop
for ADDRESS in `cat /dir/notify`
do
USERNAME=` echo $ADDRESS| cut -d@ -f1 `
echo "$USERNAME, database is going down" | mail $ADDRESS
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 12:01 AM
тАО09-27-2002 12:01 AM
Re: Shell script - while do loop
# ./awks
awk: The string echo %s, d cannot contain a newline character.
The source line is 1.
The error context is
{name=$1; email=$0; printf("echo %s, database is go >>>
<<<
syntax error The source line is 2.
awk: The statement cannot be correctly parsed.
The source line is 2.
./awks[4]: -i: not found.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 12:05 AM
тАО09-27-2002 12:05 AM
Re: Shell script - while do loop
This message uses a character set that is not supported by the Internet Service. To view the original message content, open the attached message. If the text doesn't display correctly, save the attachment to disk, and then open it using a viewer that can display the original character set.
Then when you open the attachment it has the whole thing in there:
Received: from blah.com([19.150.203.126]) by blah.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2655.15)
id TTXP9425; Fri, 27 Sep 2002 04:08:06 -0400
Received: (from root@localhost) by blah.blah.com (8.7.1/8.7.1) id JAA07720 for me@blah.com; Fri, 27 Sep 2002 09:09:04 +0100 (BST)
Date: Fri, 27 Sep 2002 09:09:04 +0100 (BST)
From: root@blah.com
Message-Id: <200209270809.JAA07720@blah.com>
To: me@blah.com
Subject: database is going down
Mime-Version: 1.0
Content-Type: text/plain; charset=X-roman8
Content-Transfer-Encoding: 7bit
me, database is going down