LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to include command results to send to admins via mail (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-include-command-results-to-send-to-admins-via-mail-820242/)

deibertine 07-16-2010 01:22 PM

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

rayfordj 07-16-2010 01:58 PM

Without knowing more about your script specifically...

Code:

service dhcp3-server status | mail -s dhcp3-server deibertine@deibertine.local

mcopadis 07-16-2010 01:58 PM

mailing results from a script
 
try this:
service dhcp3-server status | mailx -s "system status" user@domain.com

deibertine 07-19-2010 02:33 PM

Quote:

Originally Posted by mcopadis (Post 4035609)
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?

repo 07-19-2010 02:39 PM

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

deibertine 07-20-2010 05:15 PM

Quote:

Originally Posted by repo (Post 4038485)
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?

timsgreen 07-20-2010 07:28 PM

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


All times are GMT -5. The time now is 07:02 AM.