PDA

View Full Version : cron and sleep and fetchmail... can you?


scott_manelis
01-29-2002, 02:00 AM
Hey there,

I recently became fed up with the amount of spam I receive and now use procmail (SpamBouncer) to filter it out.

If I use cron to run fetchmail, my Mac will never go to sleep. Fetchmail does have a daemon mode, but the daemon does not wake-up up after the Mac is asleep.

Is there a way to have a cron entry run ONLY if the Mac is awake? Or, Is there a way to have fetchmail wake-up after the Mac is awake?

Thank in advance

mervTormel
01-29-2002, 02:56 AM
i think what you might try is anacron. it's available thru the fink open source porting efforts, ( q.v. http://fink.sourceforge.net/ )

from the anacron man pages:

Anacron can be used to execute commands periodically, with
a frequency specified in days. Unlike cron(8), it does
not assume that the machine is running continuously.
Hence, it can be used on machines that aren't running 24
hours a day, to control daily, weekly, and monthly jobs
that are usually controlled by cron.


it's a smarter cron that deals with this very issue. tho, i'm not sure about the frequency reference here. does that mean that if you want anacron to run a command every hour, you'll need 24 seperate entries for the command?

let us know if this is a solution.

scott_manelis
01-30-2002, 03:23 AM
mervTormel> i think what you might try is anacron.

> Anacron is not an attempt to make cron redundant... It isn't a full-time daemon. It has to be executed from boot scripts, from cron-jobs, or explicitly. (anacron.sourceforge.net)

Thanks, but unfortunately, the cron entry prevents the Mac from sleeping, so I can't use cron to run anacron, or check mail without keeping the Mac awake.

Thanks

phlbbrtn
01-31-2002, 09:18 PM
I have cron do fetchmail and never have a problem putting the machine to sleep. I have an applescript and direct osascript to run the applescript -- of course I have to manually input the osascript but I suppose there is a way around that.

Create an applescript application "Sleep":

tell application "Finder"
sleep
end tell

A shell script "snooze.sh":

#!/bin/sh
sleep $* #put the number of seconds as command argument
osascript /path/to/Sleep

Then if you (for example) want it to go to sleep in 2 hours you enter "snooze.sh 7200 &" in the terminal.

When the machine wakes up all the cron jobs resume just fine.

I have not figured out how to get cron to run an osascript command yet but someday I will.

Titanium Man
02-01-2002, 01:48 AM
I'm SURE I'm putting my foot in my mouth here, but I think you can run scripts with the freeware app cronix, in case you hadn't heard of it.

scott_manelis
02-01-2002, 03:38 AM
Originally posted by phlbbrtn
I have cron do fetchmail and never have a problem putting the machine to sleep.
The problem is not putting the Mac to sleep while cron is running, the problem is that while cron is running the Mac cannot put its self to sleep via Energy Saver, as the cron shows up as user activity.

scott_manelis
02-01-2002, 03:40 AM
Originally posted by Titanium Man
I'm SURE I'm putting my foot in my mouth here, but I think you can run scripts with the freeware app cronix, in case you hadn't heard of it.

CronniX is a great interface to cron, but cron will prevent the Mac from sleeping, or wake it.

Titanium Man
02-01-2002, 01:15 PM
DOH!! Mmm that foot sure does taste good. Sorry, I should have stuck with replying to the original post rather than the replies! Please let us know if you find anything, because I have been looking into doing what you're trying to do as well.

mervTormel
02-01-2002, 02:38 PM
Originally posted by scott_manelis
If I use cron to run fetchmail, my Mac will never go to sleep. Fetchmail does have a daemon mode, but the daemon does not wake-up up after the Mac is asleep.

Is there a way to have a cron entry run ONLY if the Mac is awake? Or, Is there a way to have fetchmail wake-up after the Mac is awake?

Scott,

It seems that there are several problems to solve here.

1. mac sleeping; deep sleep vs. combat nap (one eye open)
2. fetchmail daemon death
3. cron's awareness


As for the mac sleeping, well, you either deep sleep and lose all functionality or don't deep sleep. Are your issues born out of deep sleeping? What hardware are you?

My G4/500 sawtooth with OEM SCSI (adaptec 2930) lost deep sleepability with OSX and was considerably fussy about it with OS9 revs.


re: fetchmail six foot dirt nap (sleep death) see #1

But, you could roll your own script to detect fetchmail death and relaunch the daemon, no?

From fetchmail man pages:

> Normally, calling fetchmail with a daemon in the background sends
> a wakeup signal to the daemon, forcing it to poll mailservers
> immediately. (The wakeup signal is SIGHUP if fetchmail is running as
> root, SIGUSR1 other- wise.) The wakeup action also clears any `wedged'
> flags indicating that connections have wedged due to failed
> authentication or multiple timeouts.
>
> The option --quit will kill a running daemon process instead of waking
> it up (if there is no such process, fetchmail notifies you). If the
> --quit option is the only command-line option, that's all there is to it.

A cron entry will only run when the mac is awake, anyway.

Cron don't have the ability to catch up unrun jobs from the past, but I think anacron do have. The ability, that is.

thoughts, anyone?

scott_manelis
02-01-2002, 08:50 PM
>Originally posted by mervTormel
>As for the mac sleeping, well, you either deep
>sleep and lose all functionality or don't deep
>sleep. Are your issues born out of deep sleeping? >
>What hardware are you?

I have a g4 466. It can go into deep sleep on its own, just not when cron tells it to wake up!

>But, you could roll your own script to detect
>fetchmail death and relaunch the daemon, no?

I could type fetchmail at the command line every time, or write a script triggered by cron, or just use cron to run fetchmail, but...

>A cron entry will only run when the mac is awake,
>anyway.

Cron will wake a Mac to perform it's job. Exactly the problem.

I'm looking to run fetchmail _only_ when my mac is _already_ awake, and to resume fetchmail after my has been asleep.

>Cron don't have the ability to catch up unrun
>jobs from the past, but I think anacron do have.
>The ability, that is.

While anacron can schedule jobs over more than 24 hours, and preform the jobs whenever it can next, anacron is still run by cron.

Thanks again, I'm still digging...

phlbbrtn
02-02-2002, 08:59 AM
>I'm looking to run fetchmail _only_ when my mac is _already_ awake, and to >resume fetchmail after my has been asleep.

I use fetchmail -- not in daemon mode though. I have it scripted and cronned to run every half hour. The iMac goes to sleep when I tell it to. When it wakes up it resumes its twice-an-hour fetchmail.

My script is a bit complex, and includes a notification routine and the Mac "speaking" when different mailboxes (sorted by procmail) have new data.

If you want the Mac to go to sleep via Energy Saver you need to space the intervals in such a way that the fetchmail intervals are wider than the Energy Saver's.

That would be trivial. Fetchmail runs every half hour so I would set the sleep interval to 20 minutes.

I don't use Energy Saver myself because I also run Seti@home. YMMV.

The shell script with osascript commands seems to me the best solution. Because I spend at least 50% of my time in Terminal it's no sweat to fire off a timer command.

One other possibility is to kill Fetchmail when you want to put the Mac to sleep. But that one still requires interaction.

bighouse
02-20-2002, 11:33 PM
I use fetchmail in daemon mode, in a B&W 400, and my Mac has no trouble going to sleep, and fetchmail works while the Mac is sleeping.

Here is .fetchmailrc:

# poll every 60 seconds
set daemon 60
#
poll mail.mem.bellsouth.net with proto pop3 user "macgames" there with password
"password" is "bighouse" here options stripcr

System sleep is set to kick in after 20 minutes and it does, but sleep does not stop fetchmail, and fetchmail does not wake the Mac up.

Perhaps your trouble is entirely due to cron. I dunno.

--Hoop