Go Back   openSUSE Forums > Archives > SF Archives > ARCHIVES - Software
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

 
Page 1 of 2 1 2
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-Mar-2008, 08:45
badger_fruit
Guest
 
Posts: n/a
Default

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
}
i then tried to send mail using the command mailx -s "test" -r "from.address@mydomain.com" recipient.address@targetdomain.com but It didn't actually do anything. I then pressed control-c to cancel it said (Interrupt -- one more to kill letter). Control-c once more dropped me back to the command line. The recipient address never received the email.

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
  #2 (permalink)  
Old 04-Mar-2008, 11:09
badger_fruit
Guest
 
Posts: n/a
Default

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
}
2. changed the command line to
Code:
 printf "Message Body Text" | mailx -send -A myaccount -s "Email subject"**recipient@thedomain.com
and now, I get emails

The only problem I have now is specific to Nagios (which is why I need the mailx to work!)

**THREAD CAN NOW BE CLOSED**
  #3 (permalink)  
Old 04-Mar-2008, 16:07
ken_yap
Guest
 
Posts: n/a
Default

Doesn't nagios have built-in mailout facilities?
  #4 (permalink)  
Old 05-Mar-2008, 03:07
badger_fruit
Guest
 
Posts: n/a
Default

Quote:
Doesn't nagios have built-in mailout facilities?
[/b]
I thought it did but after checking a few config files, it throws its variables at mail/mailx which, in turn, fire them off to the recipient(s). Unless I am mistaken of course (which is totally possible )
  #5 (permalink)  
Old 05-Mar-2008, 03:29
ken_yap
Guest
 
Posts: n/a
Default

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.
  #6 (permalink)  
Old 05-Mar-2008, 05:44
badger_fruit
Guest
 
Posts: n/a
Default

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.
  #7 (permalink)  
Old 05-Mar-2008, 06:08
ken_yap
Guest
 
Posts: n/a
Default

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
  #8 (permalink)  
Old 05-Mar-2008, 07:16
badger_fruit
Guest
 
Posts: n/a
Default

Quote:
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
[/b]

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 .....
  #9 (permalink)  
Old 05-Mar-2008, 07:44
ken_yap
Guest
 
Posts: n/a
Default

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.
  #10 (permalink)  
Old 05-Mar-2008, 08:29
badger_fruit
Guest
 
Posts: n/a
Default

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
it seems to be in the format
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.
 
Page 1 of 2 1 2

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2