LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Scripting (https://www.linuxquestions.org/questions/linux-newbie-8/scripting-914692/)

ekcr 11-21-2011 07:44 AM

Scripting
 
Linux gurus I am asking for your appreciated assistance. I am still new to linux. I need a script which sends an email after every 15 miniutes to a certain address. the email should have the output of the top command.

I think also there should be a crontab to execute the script after every 15 minutes. I woould appreciate whatever form of help/advice you can give me.

Thanxs in advance

colucix 11-21-2011 08:05 AM

You can try sendmail to send a message. A script might be simply something like this:
Code:

#!/bin/bash
(
 echo "From: Me <me@domain.com>"
 echo "To: You <you@domain.com>"
 echo "Subject: Testing mail from crontab"
 echo
 echo "This is a mail automatically sent at $(date)"
 echo
 top -b -n1
) | /usr/sbin/sendmail you@domain.com

The parentheses serve to group the echo and the top statement together (this equals to execute a subshell). To run it automatically every 15 minutes, first give execution permissions to the script:
Code:

chmod +x /path/to/script.sh
then edit the user's crontab by means of
Code:

crontab -e
and finally create your cron job:
Code:

0,15,30,45 * * * * /path/to/script.sh
Useful man pages to check:
Code:

man top
man crontab
man 5 crontab

The parts in grey must match your real situation (e-mail addresses, path and name of the script and so on). Hope this helps.

ekcr 11-22-2011 01:19 AM

Thank you very much for your help! With that kind of help it shows there are people out there who are not selfish with their knowledge.

salemhouda 11-22-2011 03:08 AM

Code:

echo "test" |mail -s test you@domain.com

TB0ne 11-22-2011 08:42 AM

Quote:

Originally Posted by ekcr (Post 4530463)
Thank you very much for your help! With that kind of help it shows there are people out there who are not selfish with their knowledge.

And Google isn't selfish either. I'm glad you got help, but this isn't the place to come to get scripts written for you. Google has MANY examples of scripts, tutorials on how to write your own, and man pages on cron which tell you how to set it up.

If you're stuck, we are always happy to assist. But you do need to write your own scripts.

colucix 11-22-2011 09:12 AM

Erroneously sent as reported post:
Quote:

Originally Posted by ekcr (Post 4530463)
@TB0ne: Thank you for your advice.



All times are GMT -5. The time now is 12:36 AM.