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
 
LinkBack Search this Thread
Old 07-16-2010, 01:22 PM   #1
deibertine
Member
 
Registered: Mar 2009
Posts: 222

Rep: Reputation: 30
How to include command results to send to admins via mail


Hi all,
I was wondering on how to include my command results in a script?
Basically what the script does is it checks the status of a service within the linux server, then sends an email when done.
I want to include the results of my status check to my mail when sent.

i.e.
service dhcp3-server status
Status of DHCP server: dhcpd3 is running. <---this I want to include in the mail that is sent out via script.

Please advise.

Cheers!
DB
 
Old 07-16-2010, 01:58 PM   #2
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 475

Rep: Reputation: 73
Without knowing more about your script specifically...

Code:
service dhcp3-server status | mail -s dhcp3-server deibertine@deibertine.local
 
Old 07-16-2010, 01:58 PM   #3
mcopadis
LQ Newbie
 
Registered: Apr 2010
Posts: 2

Rep: Reputation: 0
mailing results from a script

try this:
service dhcp3-server status | mailx -s "system status" user@domain.com
 
Old 07-19-2010, 02:33 PM   #4
deibertine
Member
 
Registered: Mar 2009
Posts: 222

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by mcopadis View Post
try this:
service dhcp3-server status | mailx -s "system status" user@domain.com

So if i want to include the result of my command:
service dhcp3-server status

Result:
Status of DHCPServer: dhcp3 is running

How do i capture the "result" to include in my mail being sent out?
 
Old 07-19-2010, 02:39 PM   #5
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Slackware 14.0
Posts: 8,464

Rep: Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877
you could create a script
Code:
echo Status of DHCPServer:  > temp.txt
service dhcp3-server status >> temp.txt
Then cat temp.txt in the mail

Last edited by repo; 07-19-2010 at 02:40 PM.
 
Old 07-20-2010, 05:15 PM   #6
deibertine
Member
 
Registered: Mar 2009
Posts: 222

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by repo View Post
you could create a script
Code:
echo Status of DHCPServer:  > temp.txt
service dhcp3-server status >> temp.txt
Then cat temp.txt in the mail
How do you "cat" the log file and include in the mail?
 
Old 07-20-2010, 07:28 PM   #7
timsgreen
LQ Newbie
 
Registered: Mar 2006
Posts: 14

Rep: Reputation: 2
By 'cat' the log file he means send it to stdout, then pipe it to the 'mail' command.

For example:

cat temp.txt | mail -s "Mail Subject" user@domain.com

This will make the contents of 'temp.txt' the body of your email.
Hope this helps,

-Tim
 
1 members found this post helpful.
  


Reply

Tags
mail


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Grep Recursive Search Results Send To E-mail or Log? Knucklehead00 Linux - Newbie 2 06-05-2009 10:19 AM
Debian etch - Unable to send mail from command line or from php mail command lqforumuser Linux - Newbie 1 03-01-2009 06:56 AM
Want to send mail with php mail() command - minimum config required? FeathersMc Linux - Server 2 10-26-2008 12:21 AM
can mail command be used to send mail onto global mail servers like yahoo etc dale_chip Linux - Newbie 4 08-12-2008 08:33 AM
command line email client to send mail to remote mail server dhanju Linux - Software 1 03-07-2008 06:37 AM


All times are GMT -5. The time now is 03:41 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration