LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-08-2005, 07:20 PM   #1
kpelczar
LQ Newbie
 
Registered: Aug 2004
Location: New York City
Distribution: redhat ES 2.1
Posts: 1

Rep: Reputation: 0
Write a script to send an email from bash


Hello everyone,

Can someone help me write a script that would send an email to my outside account every two hours from my Linux server. (Please don't ask me why :-) it is a long story). I was thinking about scheduling a job in crontab and just have the script execute every two hours.

I also need to have a subject filed to populate a current date and time in the email that will be sent from the server. I am running RH9 and please let me know if I need to set up send mail or any other type of a email relay in order to make this work.

Thanks in advance for any help or comments.

Rgs.

Konrad,
 
Old 02-08-2005, 08:22 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,977
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Code:
echo "Still alive...  Yours sincerely, Server" | mail -s "2 hours up (again)" me@work.com
And chances are that you'll have to set-up
sendmail or some other MTA ...


Cheers,
Tink
 
Old 02-09-2005, 03:07 AM   #3
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 46
i got my system to send me an e-mail using my gmail account to tell me what apollon has downloaded
 
Old 02-09-2005, 11:30 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,977
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Quote:
Originally posted by heema
i got my system to send me an e-mail using my gmail account to tell me what apollon has downloaded ;)
And if you had shared with us "how" that post
would have been valuable ;)


Cheers,
Tink
 
Old 02-09-2005, 02:00 PM   #5
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 46
sorry i was at work so i didnt have it

Here is how to make mutt send email using ur gmail account

1) Logon to ur gmail account , in settings -> Forwarding and POP
enable pop for all mail

2) Download nbSMTP (nbSMTP is a simple SMTP)
NOTE : u have to have openssl , libssl-dev installed

http://nbsmtp.ferdyx.org/

3) setup mutt by making a file named .muttrc in my HOME

here is mine :

set folder=~/Mail
folder-hook . "my_hdr From: <username@gmail.com>"
set sendmail="/usr/local/bin/nbsmtp -U username -P password -d gmail.com -h smtp.gmail.com -f username@gmail.com -p 587 -M p -S"

NOTE : ofcourse u have to enter ur username and password

Finally test it out by typing :

echo "It Works" | mutt -s "It Finally works" heematux@gmail.com


as for recieving here is a site i have found :

http://home.nyc.rr.com/computertaijutsu/mutt.html

and here is my script :
Code:
#!/bin/bash
#
# Apollon check script
#
#
# To use it type :  ./check.sh filename
#


FILENAME=(*."$1"*)

FILENAME2=$(ls | grep "$1")

FILENAME3=${FILENAME2#*.}


echo -e "\033[0;31mRunning script now\033[0m"

while true; do

if [ -f "$FILENAME3" ]; then

    echo "File $FILENAME3 downloaded"  | mutt -s "File Downloaded" email@gmail.com
    exit

elif [ -f "$FILENAME" ]; then

    echo "File $FILENAME is still being downloaded"

else
    echo "File not found"
    exit
fi

sleep 300       # sleeps for 5 minutes then checks again
done

Last edited by heema; 02-09-2005 at 02:04 PM.
 
Old 02-09-2005, 04:19 PM   #6
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 51
python will send mail real easy without using local MTA if that is to your liking
i give a down and dirty example that may not work lest i be acused of
not sharing
Code:
#!/usr/bin/python
import  smtplib
server = smtplib.SMTP("smtp.address.net")
server.sendmail('to@server.com', 'from@myserver.net', "Help, I've Fallen and i can't get up !")
server.quit()
 
  


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
Script to send email... bfloeagle Linux - General 5 10-13-2009 10:20 AM
write a shell script to send email yenonn Programming 4 02-11-2005 10:06 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
script to send email message meluser Programming 2 03-26-2003 12:35 AM
i am tryin to write a script that will send data to MySQL rhuser Programming 7 03-06-2003 03:17 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration