LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-02-2008, 12:01 PM   #1
philosophia
Member
 
Registered: Jun 2006
Posts: 54

Rep: Reputation: 15
Email script


Code:
#!/bin/bash
echo "test" | mail -s testsubject user@domain.com
I have a little one liner script that sends an email message - what's the best way to set it up so that this script sends mail for about 2 hours? wrap the mail line in a large for loop?

I may want to also vary the rate of sending. Any ideas?
 
Old 05-02-2008, 01:39 PM   #2
Guitarist88
Member
 
Registered: Feb 2004
Location: Nz
Posts: 240

Rep: Reputation: 30
You could use cron to schedule the script to run.
 
Old 05-02-2008, 03:06 PM   #3
philosophia
Member
 
Registered: Jun 2006
Posts: 54

Original Poster
Rep: Reputation: 15
problem with using crontab is that you can only set it to send every minute - I'd probably need to send faster than that for my testing.
 
Old 05-02-2008, 03:12 PM   #4
Guitarist88
Member
 
Registered: Feb 2004
Location: Nz
Posts: 240

Rep: Reputation: 30
You could use the date command:
date +%s returns the amount of seconds since the Epoch. So you can just get the value of your start time and if you want to go for 2 hours you just keep checking the date +%s until it equals your start time plus (2*3600sec/hr).
 
Old 05-02-2008, 06:30 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
A loop should work. If you want to vary the rate you could choose two signals for rate up / rate down and use 'trap' to catch them.
 
Old 05-05-2008, 08:21 AM   #6
philosophia
Member
 
Registered: Jun 2006
Posts: 54

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by unSpawn View Post
A loop should work. If you want to vary the rate you could choose two signals for rate up / rate down and use 'trap' to catch them.
a loop of 1 to a really large number? or a loop that checks the date?
 
  


Reply



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
Creating an email script? DrDoug Linux - Newbie 10 05-17-2007 06:21 AM
How to send an email within a script??? johnsanty Programming 19 09-02-2006 12:43 PM
script for email modification Ateo General 1 08-29-2006 05:00 PM
email me my IP script linuxRules Linux - General 1 11-12-2002 09:36 AM
Email Script Sathe Linux - Newbie 3 10-22-2001 07:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:26 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
Open Source Consulting | Domain Registration