|
||||||
| Forums FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| ARCHIVES - Software Questions about use, installation, or configuration of software running on SUSE Linux |
|
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
hello
i need to send email from a command line instead of gui i found /usr/bin/mail and /usr/bin/mailx and I read the man pages but they didn't really help. I read somewhere that I need to creat a .mailrc file in my home directory which I did as below:- Code:
account myaccount{
set smtp=192.168.100.2
}
Any suggestions or advice please? edit: just to add i repeated that command above but this time added "-a myaccount" to the end of the command-string; although that didn't seem to do anything, i did notice that when i pressed enter, i could type things (i presume the email body?) and pressing control-d returned "EOT" and back to the command prompt. The recipient however, still did not get an email
|
|
|||
|
So I've been working on this since my last post and I now have it sussed (well, almost!)
1. edited the .mailrc file to:- Code:
account myaccount{
set record=+Sent
set from="nagios.admin@mydomain.com (Nagios Admin)"
set smtp=192.168.100.2
}
Code:
printf "Message Body Text" | mailx -send -A myaccount -s "Email subject"**recipient@thedomain.com ![]() The only problem I have now is specific to Nagios (which is why I need the mailx to work!) **THREAD CAN NOW BE CLOSED** |
|
|||
|
Quote:
)
|
|
|||
|
Hmm, looks like you're right, it uses an external command to do mail notifications. You could also use the embedded Perl interpreter with a Perl mail module I think.
|
|
|||
|
lol, i'm sure i could, but i'd rather not spend time learning/writing perl scripts when it *should* work with mail/mailx
the general consensus from the FAQ's is that my mailx or the command.cfg file is incorrectly configured, however, if i drop into a shell (using putty from my windows machine) and replace the variables in the command.cfg file with actual words and a valid email address; the email is sent. There are no errors in the nagios logs either, it appears to have worked (although the lack of an email says otherwise!), unfortunately, their forum is like a ghost town and getting an answer is almost impossible lol I think it may be something to do with mailx needing a .mailrc file in the home folder of the user. I came to this conclusion as I log into putty as root and there is a .mailrc file in the folder /root/ I am guessing this is why a manual prinf "Test email body" | mailx -send -A mpl -s "Test email subject" recipient@domain.com works, however, when logged into nagios-web page or leaving the machine to run itself, it doesn't know which user to use to send mail via mailx. |
|
|||
|
Well nagios probably runs as the nagios user. I've never needed a .mailrc file to use mailx though. According to the man page, mailx will invoke sendmail as a child process to send the mail.
And your invocation looks suspect according to the man page.There is no option called -send. Something like this should just work: echo "Hello there" | mailx -s "Subject" sombody@example.com |
|
|||
|
Quote:
hey ken the key to mailx working (on my install at least) seems to be the -A {account} switch; without that, it did not send anything, put it back in and within a few seconds, the email dropped into my mailbox. i wonder if it's a permission thing on the mailrc file; i chown'd it to nagios and just chgp'd it to nagcmd; let's give it another try ..... |
|
|||
|
It's hard to tell what the problem is unless you run the command as the nagios user. Otherwise you'll never know which fiddle actually does anything. You may need to change the shell of the nagios user to something like /bin/bash temporarily to be able to start an interactive shell as nagios with su - nagios.
I really doubt if ~/.mailrc is required, the defaults are usually sane. |
|
|||
|
nope, it seems that ~/.mailrc *IS* required; without the -A {account}, it does not send at all, put that in (still without .mailrc) and it complains that it does not know {account}
i've replaced the mailrc file (i had renamed it for testing if it was needed or not) and tried again, i received the email. these tests were performed logged in as the user "nagios". what is confusing is the nagios.log file; it does not show any errors but also, doesn't look quite right Code:
[1204725109] SERVICE NOTIFICATION: nagiosadmin;3mplanet-db01;WIN - Drive Space N:;CUSTOM (CRITICAL);notify-service-by-email;n:\ - total: 33.08 Gb - used: 30.19 Gb (91%) - free 2.89 Gb (9%);Richard Peac***;test recipient(from contact.cfg); server; problem-area; message-type; delivery-method-or-command; subject; sender; email-body i suppose it could be something in the macro/command "notify-service-by-email" although I wrote that from scratch once I had figured out the mailx syntax. |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|