Reputation: 4577
've been puzzling over cronjobs for the last few hours. I've read documentation and examples. I understand the basics and concepts, but haven't gotten anything to work. So I would appreciate some help with this total noob dilemma.
The ultimate goal is to schedule the execution of a django function every day. Before I get that far, I want to know that I can schedule any old script to run, first once, then on a regular basis.
So I want to: 1) Write a simple script (perhaps a bash script) that will allow me to determine that yes, it did indeed run successfully, or that it failed. 2) schedule this script to run at the top of the hour
I tried writing a bash script that simple output some text to the terminal:
#!/bin/bash
echo "The script ran"
Then I dropped this into a .txt file
MAILTO = *****.******@gmail.com
05 * * * * /home/vadmin/development/test.sh
But nothing happened. I'm sure I did many things wrong. Where do I start to fix all of this?
Upvotes: 0
Views: 580
Reputation:
Crontab does not send emails by itself, and defining MAILTO
variable doesn't change its mind. You need to do something like this:
First, make sure that mail -s ADDRESS
is actually of sending email from your box.
Then invoke crontab -e
to edit crontab file. Put something like this:
SHELL=/bin/bash
[email protected]
BASH_ENV=/home/dude/.bash_profile
05 * * * Mon-Fri echo "Hello from Cron script" | mail -s "My Script Output" "${MAILTO}"
Save the file and close editor, cron should pick up changes. This should work and you should get email. Then you can replace echo "Hello from Cron script"
with your script.
Hope it helps. Good luck!
Upvotes: 1