Script to Execute command and mail results


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to Execute command and mail results
# 1  
Old 05-04-2013
Script to Execute command and mail results

HI everyone,
I would like to have a script to run a certain linux command and mail the results or output of this command.
This shell is to be later on set as cronjob.
thanks in advance.
# 2  
Old 05-04-2013
Welcome to the forum.

You solution depends on the type of system and the utility available on it.

Generally, if mailx is available, it should look like..


Code:
command | mailx -s "subject" test@abc.com

Assuming, smtp is configured on the system.
# 3  
Old 05-04-2013
Yes, I agree with CLX, before implementing this line of code, first check which mail command is install on your system. There are some commands for mail :
mail, mailx. pine, mutt etc

to check the command availablity
use
Code:
whereis command1 command2 .....

if you got the o/p for any, that is installed on your system
# 4  
Old 05-05-2013
I am not worried about the mail command. I want to run a command and send it's results/output by mail.
For example i want to run the command "df -h" every hour and send it's results by mail.
# 5  
Old 05-05-2013
Quote:
Originally Posted by patrickminas
I am not worried about the mail command. I want to run a command and send it's results/output by mail.
For example i want to run the command "df -h" every hour and send it's results by mail.
OK, so you are not worried about mail or cronjob.

So can you tell us what you are "worried" about?
# 6  
Old 05-05-2013
Any cronjob's output is mailed to the respective user, unless you take special action. So - place your command into your crontab and wait for the mails to drop in...
# 7  
Old 05-05-2013
Can you just guide me on doing that please?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. Shell Programming and Scripting

Script to Run Multiple Systems Checks and mail me the results after every reboot- Linux

Hello, I'm trying to create a mechanism wherein a set of Production servers will email me the results of system checks like Uptime, NFS Mounts and a Process after every scheduled reboot. For this, I figured I'd use the @reboot parameter that crond comes with. I have added the below onliner... (3 Replies)
Discussion started by: pocodot
3 Replies

3. Shell Programming and Scripting

ksh script find command not printing any results

Hello, Hitting a wall on this one. When at the command prompt it works fine: # find /home/testuser -name 'PAINT*canvasON.txt' /home/testuser/PAINT_canvasON.txt # pwd /home/testuser # ls -l PAINT*canvasON.txt -rw-r--r-- 1 root user 23 Feb 07 02:58 PAINT_canvasON.txt... (2 Replies)
Discussion started by: seekryts15
2 Replies

4. Shell Programming and Scripting

[Solved] Shell script output in HTML or with table like results and mail

Hello, Currently i have a script which will disply the results in plain text format. I want to format the result in more readable format like Making bold headings and format with colors etc. Something like html and send that content as email. Please help me how i can do that. I am using... (10 Replies)
Discussion started by: joy lobo
10 Replies

5. Shell Programming and Scripting

Script runs but does not execute rm -rf command

Hi! First off I'm no bin/bash script writer! :( I can make heads and tales of it from the php experience I have and that's all. Now I managed to piece this script together to go look at directory and remove files that are +60 days. It's finding the files but its not removing them. I... (11 Replies)
Discussion started by: MrBiggz
11 Replies

6. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

7. Shell Programming and Scripting

How can I execute the results of a pipe?

Hello, I'm using csh. I have a file named "setup" that I normally source, e.g. source setupI'd like a one-liner that sources this file, but excluding lines that contain "DEBUG", e.g. cat setup | grep -v DEBUG | sourceOf course, the above does not work. How can I execute the results of a... (5 Replies)
Discussion started by: acheong87
5 Replies

8. Shell Programming and Scripting

Backing out of a script if command doesn't return any results?

Hello I have a script which emails identifies the user ID of a user and sends them an email. A user can enter part of the name of the person he/wants to send the email to. Then I use the ypcat command to identify the UID of that person. The problem I'm having, is building in an error trap... (1 Reply)
Discussion started by: Glyn_Mo
1 Replies

9. Shell Programming and Scripting

how to execute a sh command from a csh script

Hi everyone, I have a csh script that works fine but the output of an rsh command is different if I use boune shell instead cshell. Is there the possibility to execute only this command in bourne shell from a script declared cshell? Thanks Christian (2 Replies)
Discussion started by: bonovox
2 Replies

10. Shell Programming and Scripting

script to run shell command and insert results to existing xml file

Hi. Thanks for any help with this. I'm not new to programming but I am new to shell programming. I need a script that will 1. execute 'df -k' and return the volume names with specific text 2. surround each line of the above results in opening and closing xml tags 3. insert the results of step... (5 Replies)
Discussion started by: littlejon
5 Replies
Login or Register to Ask a Question