LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-14-2016, 11:30 AM   #1
pylkko
LQ Newbie
 
Registered: Jun 2015
Posts: 11

Rep: Reputation: Disabled
Automatically send email at the end of month but on computer that is not on all the time


I have been reading on this and am not entirely sure what the best way to do this is. What I need to do is have a script (which does nothing more than collects some data and sends it in an email) run once a month. However, it cannot be run earlier than, say, the 25th day of the month. Also, this is on a laptop that is not on 24/7 nor necessarily used daily.

So, I see that cron would not be good for this, since if the computer is off when the event occurs it will not perform the task. Anacron, on the other hand, can act so that it performs the task when it first can at some specific interval. Anacron, however, apparently does not allow for more specific timing than "once a month", in other words I cannot specify that I want this to occur within the last 5 days or so of the month, and not in the beginning.

I read a proposal on the net that one can have a daily cron job query the day and then use a logical comparison such as "is date > 25" and if not then exit, otherwise perform task. However, to me this seems a bit odd, that is to perform a task 30 times a month for an email that needs to be sent once. Is there some better way?

Last edited by pylkko; 03-14-2016 at 11:57 AM. Reason: typo
 
Old 03-14-2016, 12:23 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I don't think that's a bad way; however what if the computer is also not turned on between the 25th and the end of the month? Perhaps also record the last day a report was sent and if it has been longer than 25-30 days, consider making a new report for that condition too.
 
Old 03-14-2016, 01:19 PM   #3
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Sorry, misread post and confused myself.

Last edited by norobro; 03-14-2016 at 04:37 PM.
 
Old 03-14-2016, 09:28 PM   #4
pylkko
LQ Newbie
 
Registered: Jun 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
I don't think that's a bad way; however what if the computer is also not turned on between the 25th and the end of the month? Perhaps also record the last day a report was sent and if it has been longer than 25-30 days, consider making a new report for that condition too.
I am almost 100% sure that that will never happen, that is, that this particular computer will never be unused for so many days in a row. However, just to be safe the script could "have memory", in other words, maybe something like i = i + 1 after the performance. After that it would need to check on two conditions prior to performing the deed 1) is i > 0 and 2) is date > 25. Also, of course, would require zeroing i on the fist day of every new month some how.


Maybe it is not a problem to have a script run like this "all the time". It's not like it's going to eat a lot of cpu cycles or something.

This laptop also runs systemd, and thus maybe could do this same thing using a .timer

Last edited by pylkko; 03-14-2016 at 09:31 PM.
 
Old 03-14-2016, 10:17 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by pylkko View Post
Maybe it is not a problem to have a script run like this "all the time". It's not like it's going to eat a lot of cpu cycles or something.
I agree and that's exactly what I was saying which is that I do not believe it is a huge deal to run a script every time you boot, if it has nothing much to do, then that's all of it, and the one time per month it needs to do it's work, it is primed to accomplish that task and then go into reduced mode for the next month's time.

Are you by chance saving log files of some type? I've never configured exactly stuff like this, but I believe you can use logrotate to do some of this stuff and in fact, remove the one month item and just go by log file size instead. You clearly can run a script post rotating of files to send a mail.
 
Old 03-14-2016, 10:52 PM   #6
pylkko
LQ Newbie
 
Registered: Jun 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
I now realize that systemd already has all these functions implemented in it. That is, it is possible to set a day of the month at which to perform task (and the computer can be off), it can send a mail in case of problem, and also the Persistent = true option can even store the last time the task was performed on disk and use that to decide what to do. And it is as easy as making a normal .service and then running that with a .timer.

The stuff that I am collecting are not logs, but other work that people have done, so logrotate is not going to work here.

Last edited by pylkko; 03-14-2016 at 10:55 PM. Reason: typos
 
  


Reply



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
A program to automatically send email to some user Peter_APIIT Linux - General 5 12-17-2007 04:37 AM
automatically send an email to new users....? oru Slackware 2 09-14-2007 02:56 AM
Looking for a way to automatically send current real IP to email anakganteng Linux - Newbie 8 07-06-2006 12:22 PM
Send email from computer Awatto Linux - Newbie 1 12-17-2003 02:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:29 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration