Solved

Script waiting for CTRL+D command after mailx

Posted on 2007-11-30
7
1,240 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now