LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-21-2011, 08:44 AM   #1
ekcr
LQ Newbie
 
Registered: Nov 2011
Posts: 9

Rep: Reputation: Disabled
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
 
Old 11-21-2011, 09:05 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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.
 
1 members found this post helpful.
Old 11-22-2011, 02:19 AM   #3
ekcr
LQ Newbie
 
Registered: Nov 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
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.

Last edited by ekcr; 11-22-2011 at 02:20 AM.
 
Old 11-22-2011, 04:08 AM   #4
salemhouda
LQ Newbie
 
Registered: Nov 2011
Posts: 8

Rep: Reputation: Disabled
Code:
 echo "test" |mail -s test you@domain.com

Last edited by salemhouda; 11-22-2011 at 04:15 AM.
 
Old 11-22-2011, 09:42 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,265

Rep: Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440
Quote:
Originally Posted by ekcr View Post
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.
 
Old 11-22-2011, 10:12 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Erroneously sent as reported post:
Quote:
Originally Posted by ekcr View Post
@TB0ne: Thank you for your advice.
 
  


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
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 05:02 AM
Firefox Scripting Add-on (Scripting HTML / Javascript inside Firefox) linuxbeatswindows Programming 1 09-18-2009 11:09 PM
Scripting atul_sp Linux - Server 1 02-05-2008 12:45 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
scripting bforest Linux - Newbie 4 05-11-2004 03:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:11 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