I am attempting to create an online estimate scheduler for my company. I am creating a database full of times for a one week period. There will be associated check boxes with these database entries and if a user selects a date and time I plan to drop the specified time from the database and then send an email to my account with their provided information as well as the time. I want the database to automatically reset each 7 days so that all times are available for that week. I am having a couple of issues....
I am using mySQL and python for the scripting. I can not figure out how to mail to myself, and I do not know how to periodically reset the database without my intervention. If you guys could shed any light on this it would be greatly appreciated. Thanks for the help guys!
E-mail could be taken care of using the smtplib and email modules. These two example links may help: Example1, Example2.
As far as "periodically" doing things, you'll find that cron is an amazing utility. It allows you to schedule things to happen on a recurring basis. In your case, you would develop a small script that would do the "reset" that you want and schedule it in cron to run weekly. Some good example docs are found here.
If you're running on windows instead, look into the Windows scheduler to do the same thing.
Related
The title is my question. I can't think of anything that is useful to store jobs to external database.
Can you guys provide some use cases?
thank you.
If you schedule jobs dynamically (at run time instead of adding them all at application startup), you don't want to lose them when you restart the application.
One such example would be scheduling notification emails to be sent, in response to user actions.
After researching a bit, I had to ask here.
Aim :- I need to run a python script for let's say 6 hours "daily" and whenever some condition gets satisfied in the script during that time, it should send an automatic notification to some users.
I was hoping we can do this on firebase but couldn't find anything similar to it.
Why Firebase ? Because in firebase I could send notification to specific users.
I actually created a kivy mobile app but that didn't work so yeah, if anybody has some experience or have done such kind of project I need your help please!
Thanks in advance!
I want to be able to schedule an e-mail or more of them to be sent on a specific date, preferably using GAE Mail API if possible (so far I haven't found the solution).
Would using Cron be an acceptable workaround and if so, would I even be able to create a Cron task with Python? The dates are various with no specific pattern so I can't use the same task over and over again.
Any suggestions how to solve this problem? All help appreciated
You can easily accomplish what you need with Task API. When you create a task, you can set an ETA parameter (when to execute). ETA time can be up to 30 days into the future.
If 30 days is not enough, you can store a "send_email" entity in the Datastore, and set one of the properties to the date/time when this email should be sent. Then you create a cron job that runs once a month (week). This cron job will retrieve all "send_email" entities that need to be send the next month (week), and create tasks for them, setting ETA to the exact date/time when they should be executed.
Yes, sending emails from cron jobs is fairly common, exactly for the scheduling reason.
Unfortunately controlling cron jobs programatically is not (yet) possible. You may want to star Issue 3638: Cron jobs to be scheduled programatically
Meanwhile you could check this answer for a couple of alternatives: https://stackoverflow.com/a/37079488/4495081
I am working on a project for work that requires me to pull information from a logfile and send a notification anytime it finds a the specific information. For example the exact issue I am working on is I am needing to create a python script that will look into may /var/log/auth.log (FreeBSD system) and pull any invalid SSH login attempts, then proceed to email me and another co-worker anytime there is an offense.
I've been looking all over for a few days now and have had minimal success any help would be greatly appreciated.
I think what you're really after is a daemon like fail2ban, which is specifically designed to examine log files for intrusion attempts.
From the fail2ban wiki:
Fail2ban scans log files (e.g. /var/log/apache/error_log) and bans IPs
that show the malicious signs -- too many password failures, seeking
for exploits, etc. Generally Fail2Ban then used to update firewall
rules to reject the IP addresses for a specified amount of time,
although any arbitrary other action (e.g. sending an email, or
ejecting CD-ROM tray) could also be configured. Out of the box
Fail2Ban comes with filters for various services (apache, curier, ssh,
etc).
This would probably work better than any solution you baked yourself.
That said, if you did want to roll your own, the naive way to implement periodic checking of a file is simply to read it every five minutes and see if it's changed.
The smarter way is to use the operating system's file monitoring service, which hooks into the filesystem driver and notifies you as soon as the file changes. This has the dual benefits that your code will take less CPU time, and it will respond immediately whenever the file changes.
On Linux the service is called inotify. BSD and Windows have an equivalent feature.
You could run a cron job every few minutes that checks for changes in that file. If there are any changes, it will email you, by using, for example, smtplib. Here is an example of smtplib usage with sendgrid: http://docs.sendgrid.com/documentation/get-started/integrate/examples/python-email-example-using-smtp/
How do you find out if a file was modified?
You keep a copy of the file as it looked in the previous script run, and compare that to the current contents
You check the file's last modification time.
This is just a general idea that can be tweaked, and all the 'ingredients' can be found on google, so you should be able to implement it by googling yourself.
Hope this helps.
As a rough idea for a cron job:
with open('/var/log/auth.log') as auth:
for line in auth:
if 'blahblah' in line:
# send email
You'll want to check out the email module for emailing details. You'll also want a way to keep track of what's already been scanned, so you don't end up sending duplicate emails.
I am designing a python web app, where people can have an email sent to them on a particular day. So a user puts in his emai and date in a form and it gets stored in my database.
My script would then search through the database looking for all records of todays date, retrive the email, sends them out and deletes the entry from the table.
Is it possible to have a setup, where the script starts up automatically at a give time, say 1 pm everyday, sends out the email and then quits? If I have a continuously running script, i might go over the CPU limit of my shared web hosting. Or is the effect negligible?
Ali
Is it possible to have a setup, where
the script starts up automatically at
a give time, say 1 pm everyday, sends
out the email and then quits?
It's surely possible in general, but it entirely depends on what your shared web hosting provider is offering you. For these purposes, you'd use some kind of cron in any version or variant of Unix, Google App Engine, and so on. But since you tell us nothing about your provider and what services it offers you, we can't guess whether it makes such functionality available at all, or in what form.
(Incidentally: this isn't really a programming question, so, if you want to post more details and get help, you might have better luck at serverfault.com, the companion site to stackoverflow.com that deals with system administration questions).