LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 02-13-2004, 12:20 PM   #1
MidnighToker
LQ Newbie
 
Registered: Jan 2004
Posts: 4

Rep: Reputation: 0
Question scripted job to send mail


I was wondering if anyone could help me (or point me in the direction of help) with regard to sending an e-mail twice a day.

I want to make a script that twice a day sends an e-mail to our SMS server e-mail account, specifying both subject and message, so i can keep checking that the sms server is working.

if anyone could offer any advice, it would be much appriciatted.

The Midnight Toker.
 
Old 02-13-2004, 12:34 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2393Reputation: 2393Reputation: 2393Reputation: 2393Reputation: 2393Reputation: 2393Reputation: 2393Reputation: 2393Reputation: 2393Reputation: 2393Reputation: 2393
You could use cron (man 5 crontab) for the 'twice a day part'. As you might, or might not, know, cron is a (daemoned) sheduler.
You give crontab the times and point it to a script to execute at the given times.

Hope this gets you going again.
 
Old 02-16-2004, 09:09 AM   #3
MidnighToker
LQ Newbie
 
Registered: Jan 2004
Posts: 4

Original Poster
Rep: Reputation: 0
i'd heard about this mystical cron daemon, but wasnt sure how to get going with it.

i dont suppose you know of any websites with tutorials/whitepapers or anything else i can be reading (other than the man entery) to get me going with this?

thanks, fligg
 
Old 02-16-2004, 10:58 AM   #4
skog
Member
 
Registered: Sep 2003
Location: TX
Distribution: slackware
Posts: 301

Rep: Reputation: 30
man crontab <-- always check you man files TONS of information there

info crontab <-- always check your info files TONS of information there too

crontab -e ...some pretty good notes in the crontab file itself ... if youve used vi before it just opens in the vi editor

www.tldp.org
 
Old 02-16-2004, 11:06 AM   #5
MidnighToker
LQ Newbie
 
Registered: Jan 2004
Posts: 4

Original Poster
Rep: Reputation: 0
oh brilliant.

VI(M) isnt a problem, its one of hte few things i'm happy with. As for info, its a command i've never heard of before now. Right off to play

Thanks all
 
Old 02-16-2004, 09:18 PM   #6
DaHammer
Member
 
Registered: Oct 2003
Location: Planet Earth
Distribution: Slackware, LFS
Posts: 561

Rep: Reputation: 30
Here is a perl script that you can use to send the email. It's not taylored for your specific purpose and has no error checking of any kind. But it will do the job. I use it to test new accounts sometimes.
Code:
#!/usr/bin/perl
# mailer.pl
# A simple way to send an email with perl, using Sendmail
#
# To Use:
# 1) Install/Configure sendmail
# 2) Change the below variables to your info
# 3) Change the permissions on this script to 755 (ie, chmod 755 mailer.pl)
# 4) Execute the script (ie, ./mailer.pl)

# ****************** MODIFY THE BELOW VARIABLES TO SUIT YOUR NEEDS ******************
$to='somebody@somewhere.net';      # Who the email is too
$from='you@wherever.org';          # Who the email is from
$subject="This is a test...";      # Subject of the email
$content="Testing email script.";  # Content/Body of the email
$sendmail="/usr/sbin/sendmail";    # Mailer program to use to send the email
# **************************** END OF USER MODIFICATIONS  ***************************

# Send the email
open (MAIL, "|$sendmail -oi -f$from -t");
print MAIL <<ENDOFEMAIL;
From: $from
To: $to
Subject: $subject

$content

ENDOFEMAIL

close(MAIL);

Last edited by DaHammer; 02-17-2004 at 12:41 AM.
 
Old 02-17-2004, 12:34 AM   #7
naflan
Member
 
Registered: May 2003
Location: NC, USA
Distribution: Slackware 14.0
Posts: 94

Rep: Reputation: 15
cron help:

Link

If using crontab (crontab -e), put in this entry:

min hour DayOfMonth month DayOfWeek user cmd

Ex. 00 23 01 * * /home/user/script.sh
will run script.sh at 11PM on the first of every month

Ex. 00 11,23 * * mon /home/user/script.sh
will run script.sh at 11AM and 11PM every Monday.

Ex. 05 20 * * * /home/user/script.sh | mutt -s "subject" email@address
will send the output of script.sh to email@address with subject "subject" at 8:05PM every day. (provided you have mutt installed and configured)

crontab is for user jobs. For system jobs, put a script in /etc/cron/cron.daily or cron.hourly or cron.weekly, etc.


Last edited by naflan; 02-17-2004 at 12:50 AM.
 
Old 02-17-2004, 08:39 AM   #8
MidnighToker
LQ Newbie
 
Registered: Jan 2004
Posts: 4

Original Poster
Rep: Reputation: 0
ok, this is all starting to make sense.

i'm off work untill Monday, but i'll no doubt be logging in and playing about.

thanks for all the help.
 
  


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
Server does'nt send mail until shutdown and LAN can't send or receive. Wolfy Linux - Networking 0 08-02-2004 08:31 PM
cron job to send file via ftp every 1 hour mcalizo Linux - Newbie 1 07-14-2004 04:50 AM
usin AWK in cron job to send dynamic ip via email digihlp Programming 2 12-10-2003 09:10 AM
Cron job , send email mikeshn Linux - General 1 09-21-2003 10:02 AM
Send Email + Txt Attachment Using Cron Job beringer Linux - Newbie 3 01-31-2003 11:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

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