Link to home
Start Free TrialLog in
Avatar of XOracle
XOracle

asked on

Script waiting for CTRL+D command after mailx

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
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm sure I've just answer this already!
Hi,

Don't worry :)
Avatar of XOracle
XOracle

ASKER

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!
I'd recommend that you don't use negative exit codes as that breaks the usual Unix convention of 0=success, >0=failure
Avatar of XOracle

ASKER

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