LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-12-2012, 04:32 PM   #1
tonj
Member
 
Registered: Sep 2008
Posts: 546

Rep: Reputation: 37
notify by email when command is run


I'm running centos5.8 server and I want to be notified my email when a certain command is run,
eg: # /etc/init.d/<program-name> start
Can this be done? I've set two cron jobs to 1)start and 2)stop a program but I'd like email notification when it happens. I searched on google but couldn't find anything specific to this. Thanks for any pointers.
 
Old 08-12-2012, 04:33 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Examples here http://www.tek-tips.com/faqs.cfm?fid=4611
 
Old 08-12-2012, 04:36 PM   #3
tonj
Member
 
Registered: Sep 2008
Posts: 546

Original Poster
Rep: Reputation: 37
thanks but I don't use mailx, my server uses sendmail.
 
Old 08-12-2012, 04:39 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
mailx is the client tool; sendmail is an mta; Linux uses both, just like most other *nix.
 
Old 08-12-2012, 04:57 PM   #5
tonj
Member
 
Registered: Sep 2008
Posts: 546

Original Poster
Rep: Reputation: 37
I'm surprised to discover mailx is already installed, I didn't even know it was there. It's not a very friendly app. I've been reading the manual and so far cannot see how to start it, or how to connect it to a command phrase. Are you sure mailx can do what I need?
 
Old 08-12-2012, 05:01 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Just follow the examples in my link
 
Old 08-12-2012, 05:08 PM   #7
tonj
Member
 
Registered: Sep 2008
Posts: 546

Original Poster
Rep: Reputation: 37
I tested 'echo "This is the body."| mailx -s "mailx Test1" me@mysite.com' in a console and that worked but I don't see an example of how mailx will send an email when a command like "/etc/init.d/<program-name> start" is run.
 
Old 08-12-2012, 05:13 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by tonj View Post
I've set two cron jobs to 1)start and 2)stop a program but I'd like email notification when it happens.
Sysv init scripts display status on stdout so your cron jobs should be mailing it already unless you unset the MAILTO variable. Check your mailbox?
 
Old 08-12-2012, 05:18 PM   #9
tonj
Member
 
Registered: Sep 2008
Posts: 546

Original Poster
Rep: Reputation: 37
thanks unSpawn, I created the cron jobs in the webmin gui, not in a console and webmin did not display a mailto option. I don't know whereaabouts in the console I would specify the mailto option...
 
Old 08-12-2012, 05:39 PM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
MAILTO is a default, see 'man 5 crontab'.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Lan Samba Server. Want it to notify me when disk is running low via email? Moggertron Linux - Software 2 02-05-2012 06:43 AM
Command based email client to send email through secure smtp havolinec Linux - Newbie 2 07-27-2010 07:40 AM
run a shell script/cronjob when any email arrive to specific email address ikillu Linux - General 3 05-30-2009 08:18 AM
notify uploads by email in vsftpd deeptranz Linux - Networking 2 01-11-2006 01:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration