LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 05:32 PM   #1
tonj
Member
 
Registered: Sep 2008
Posts: 383

Rep: Reputation: 24
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, 05:33 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

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

Original Poster
Rep: Reputation: 24
thanks but I don't use mailx, my server uses sendmail.
 
Old 08-12-2012, 05:39 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

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

Original Poster
Rep: Reputation: 24
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, 06:01 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

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

Original Poster
Rep: Reputation: 24
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, 06:13 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
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, 06:18 PM   #9
tonj
Member
 
Registered: Sep 2008
Posts: 383

Original Poster
Rep: Reputation: 24
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, 06:39 PM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
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 07:43 AM
Command based email client to send email through secure smtp havolinec Linux - Newbie 2 07-27-2010 08:40 AM
run a shell script/cronjob when any email arrive to specific email address ikillu Linux - General 3 05-30-2009 09:18 AM
notify uploads by email in vsftpd deeptranz Linux - Networking 2 01-11-2006 02:03 PM


All times are GMT -5. The time now is 01:28 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration