Reputation: 1865
I am wanting to write my first Python script for my Ubuntu VPS and I was wondering the best way to go about doing it. This script will send me a message every 30 minutes through my gmail account.
Originally, in my head I envisioned a Python script that would just always be running and then would email me once every 30 minutes, like a daemon I guess. Can you run a Python script like a daemon?
Now that I think about it more though, it may be better to just have a python script that is designed to be executed by crontab.
Which approach do you think is best? I realize sending an email every 30 min is an almost useless task but it is something I can build on.
Upvotes: 0
Views: 60
Reputation: 4580
The simple approach is to write your python script to use smtplib
.
def sendEmail(*args):
#send email
Here is a simple tutorial for using smtplib
Then have cron
or bash script to evoke this script every 30 minutes.
Here is a simple tutorial on cron
Personally I would just use smtplib + bash script. and the bash script would look something like:
while true
do
python sendmail.py
sleep 1800
done
Upvotes: 1