• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3022
  • Last Modified:

shell script and mailx

making a script to send a alert, can't quit figure out what to put in the  [ ] below
command work ok if done on command line, just can't put it into a script the right way

#!/bin/sh

su - pmx -c '/opt/pmx4/bin/pmx status' | grep -i dead
if [ echo = dead ]; then
  mailx -s "pmx is dead ." 777-777-7777\@text.com;
done


Thanks,
0
bt707
Asked:
bt707
  • 4
  • 2
1 Solution
 
bt707Author Commented:
one other note,
when i run the maix comand from the command line I have to
use a ctrl-d to send the message, not sure how to do that
part in a script either
0
 
tfewsterCommented:
su - pmx -c '/opt/pmx4/bin/pmx status' | grep -i dead
if [ $? -eq 0 ]; then
  mailx -s "pmx is dead ." 777-777-7777\@text.com < /dev/null
done

$? will be 0 if the last command (grep) returned "success" i.e. it found the text you were looking for

< /dev/null could also be < any_file, to tell mailx to use that file as the body of the message
0
 
bt707Author Commented:
tfewster,

that just about did it, one problem though, when i run it this way i still have the same
problem, when it gets to the  mailx command it just hangs waiting for more info,
when i hit the crtl-d it then finishes and sends the message,

how can i end this with a crt-d somehow so I don't have to do it maually.

Thanks,
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
tfewsterCommented:
Oops, taking input from /dev/null will never supply and EOF (== Ctrl-d ) - Supply a real file, e.g. /etc/issue, or some dummy text:

mailx -s "xx" someone@maildomain.com < yourfile

or even
ls | mailx -s "xx" someone@maildomain.com
0
 
TintinCommented:
or simply

echo | mailx -s "subject" user@example.com


However, using

mailx -s "subject" user@example.com </dev/null


works on Solaris and Linux (with the mail command).


What Unix flavour do you have bt707?
0
 
bt707Author Commented:
using solaris 8,   checking things again, works just fine when i run the script other than it wait for me to do
a ctrl-d before it sends out.
0
 
bt707Author Commented:
not sure what i did the first time, i think i left off the   < /dev/null

anyway I went back and recreated it just as tfewster had put it the in the first place
and all is working just fine.

Thanks a lot all,
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now