Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Script waiting for CTRL+D command after mailx

Posted on 2007-11-30
7
Medium Priority
?
1,392 Views
Last Modified: 2008-02-01
I'm trying to put together a simple script where I send myself an email if an error occurs. I have put together the following code, but when I kick off the shell script from UNIX, it just hangs and waits for me to hit CTRL+D to sned the message. What am I doing wrong here?

if [ ${?} -ne 0 ]
                      then
                        echo "There was an error"
                        mailx -s "The ${header_dat_file} file contained errors." me@domain.com
                        exit -1
           fi
0
Comment
Question by:XOracle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 300 total points
ID: 20383709
Try: -

echo | mailx -s "The ${header_dat_file} file contained errors." me@domain.com
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 200 total points
ID: 20383733
Hi,

Change it to

if [ ${?} -ne 0 ]
then
       echo "There was an error" |  mailx -s "The ${header_dat_file} file contained errors." me@domain.com
       exit -1
fi

The mailx was waiting for the message body, but with pipe it will take it from echo

0
 
LVL 40

Expert Comment

by:evilrix
ID: 20383750
I'm sure I've just answer this already!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:omarfarid
ID: 20383765
Hi,

Don't worry :)
0
 

Author Comment

by:XOracle
ID: 20384404
Thanks to both of you. I was actually about to ask why the pipe was necessary, but omar offered the explanation. Makes sense now.

Thanks again!
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20392202
I'd recommend that you don't use negative exit codes as that breaks the usual Unix convention of 0=success, >0=failure
0
 

Author Comment

by:XOracle
ID: 20399263
I'm afraid that doesn't make too much sense to me right now. The bulk of my code is coming from cut-and-paste right now, but I am trying to learn as much as I can. I've purchased a couple of books on scripting, but I am still on the basics.

Thanks again,
XOracle
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question