Solved

Script waiting for CTRL+D command after mailx

Posted on 2007-11-30
7
1,271 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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 75 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 50 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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 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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

856 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