LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Introduction and question about Cron and e-mail (https://www.linuxquestions.org/questions/linux-newbie-8/introduction-and-question-about-cron-and-e-mail-4175441038/)

Sharkadder 12-11-2012 05:43 PM

Introduction and question about Cron and e-mail
 
Hi there,

I have been using Linux systems for a number of years and have delt in many platforms including Ubuntu, Kubuntu ontop of that, Fedora and also some private based images.

Basically what it is yeah, i have some web hosting on a linux based Apache web server and have only recently started to look into using the crontab commands again (it has been a while since me using it when programming in Python).

The question i have is, i can set a cron off every hour and i will receive an e-mail about what has been executed etc. but what i wanted to know is, can i make the e-mail only be sent at midnight on the day? So the script runs 24 times in the day but i only get e-mailed from the Cron which runs at midnight.

The reason is, the web space that i rent only allows me to do one cron job and i am trying to find a way to execute it every hour but only send the e-mail for something once per day. Any solutions are great.

The Cron will be executing a cron.php file where part of this file will only execute at a certain time. I am familiar with PHP and the time functions if you think i could maybe do something with them to only send the e-mail out once a day. Just i am unsure how i can create a link in the cron.php file to e-mail out everything which is executed only at midnight.

Any suggestions are welcome...quite a puzzling question i thought for a first post from a new member lol. If this is in the wrong forum then can somebody move it please to the right section and any help is much appreciated as when doing a search on the net i have found nothing to help me with this.

chrism01 12-12-2012 12:46 AM

Quote:

the web space that i rent only allows me to do one cron job
per day ?? Seriously???
Personally I'd go elsewhere; that's ridiculous.

However, IF(!) I had to live with it I'd write a daemon to do the data gathering hourly and run the cron job once a day to send the email.
(Actually, rather than waste the cron job, I'd get the daemon to do the email as well)

Sharkadder 12-12-2012 10:23 AM

Hi Chris,

I shall look into this, the cron i have can be executed multiple times per day but i only have access to the one cron job. i.e. multiple sends but i cannot figure a way to do the cron every hour but only send the e-mail which comes with it once per day. Do you know how i can maybe resolve this? Don't think my shared hosting has access to a Daemon which is a shame, restricted access and all that etc. :-(.

Many thanks,

Mark

linosaurusroot 12-12-2012 10:49 AM

You could run a script that has different behaviour depending on factors like:
is it midnight (within a small interval)?
have I already got 23 stored outputs from previous runs?

Sharkadder 12-12-2012 12:03 PM

Hi ans thanks for the reply,

I could do your suggestion but when you do a cron command the e-mail runs from the actual command and not through any form of PHP script. That why i wondered if there was any specific parameter attached to cron.

My con job currently looks like this to let it e-mail once every day but don't know a command to make it go off every hour and only e-mail once per day:

0 1 * * * TERM="xterm"; /usr/bin/lynx -dump http://mysite.com/mycronpage.php

Many thanks :-) and let me know what you think i can do or if i am at my limit just doing it all from one command,

Mark


All times are GMT -5. The time now is 02:27 PM.