You are not logged in.

#1 2008-03-09 11:11:20

awagner
Member
From: Mainz, Germany
Registered: 2007-08-24
Posts: 191

per-user cronjob (somewhat automatically)

Hi all,
probably some of you have a solution for this already in place:
I have switched from fetchmail to mpop and miss the daemon feature. When I tried to launch mpop with the following mpop file in /etc/cron.d, it didn't work (I think it didn't download any messages, probably due to the fact that my mpoprc/mailbox definition is in my personal home dir. But even with su it didn't work.):

*/10 * * * * su wagner -c /usr/bin/mpop -qa

With the crontab command, however I can insert it in my personal crontab and it's working fine. Now should I put such a crontab command in my .profile or what?

Second, I would like to automatically enable/disable that cronjob dependng on whether I'm on-line or not, and
thirdly, I would like to be able to call mpop manually (I have a keybinding in mutt for that), but that should be a nop when the cronjob is just executing.

Thanks for any hints,
Andreas

Offline

#2 2008-03-09 11:54:56

patroclo7
Member
From: Bassano del Grappa, ITALY
Registered: 2006-01-11
Posts: 915

Re: per-user cronjob (somewhat automatically)

First, the cron daemon executes job from the crontabs of any user: so just edit the crontab of the user with 'crontab -e -u <user>' and the cron daemon will do everything.
For the verification of the internet connection, you can use a script which pings some hosts and executes the action only if the ping is successful:

#!/bin/bash
IP1=0.0.0.0           # enter an IP address here
IP2=0.0.0.0     # enter an IP address here
IP3=0.0.0.0           # enter an IP address here
IP4=0.0.0.0.        # enter an IP address here
COMMAND=$1
STATUS=Up
ping -c1 $IP1
if [ $? != 0 ]; then
        ping -c1 $IP2
        if [ $? != 0 ]; then
                ping -c1 $IP3
                if [ $? != 0 ]; then
                        ping -c1 $IP4
                        if [ $? != 0 ]; then
                                STATUS=Down
                                echo "down"
                        fi

                fi
        fi
fi

if [ $STATUS = Up ]; then
        echo "up"
        exec $COMMAND
fi

Call this script e.g. 'netex', and then use 'netex <yourdesiredaction>' as a cron job definition.

On the first point I do not know, but many mail fetchers use a lock to prevent a double execution (e.g. fdm). I do not know mpop so I do not know how to get the same result.


Mortuus in anima, curam gero cutis

Offline

#3 2008-03-09 13:17:45

awagner
Member
From: Mainz, Germany
Registered: 2007-08-24
Posts: 191

Re: per-user cronjob (somewhat automatically)

patroclo7 wrote:

First, the cron daemon executes job from the crontabs of any user: so just edit the crontab of the user with 'crontab -e -u <user>' and the cron daemon will do everything.

Is the result of that command persistent over reboots? (I thought it wasn't and wanted to avoid entering it every time on startup.)

Other than that, thanks for your script. I will surely make use of it.

Edit: modified it a bit to look like this now:

#!/bin/sh

IP1=<someIPaddy>                   # enter an IP address here
IP2=<someotherIPaddy>           # enter an IP address here
COMMAND=$@

( ping -c1 $IP1 >/dev/null 2>&1 ; ping -c1 $IP1 >/dev/null 2>&1 ) && exec $COMMAND

Last edited by awagner (2008-03-09 13:28:51)

Offline

#4 2008-03-09 13:48:24

patroclo7
Member
From: Bassano del Grappa, ITALY
Registered: 2006-01-11
Posts: 915

Re: per-user cronjob (somewhat automatically)

Sure it is, all the crontabs are persistent and a spool is managed. This both with dcron and with fcron


Mortuus in anima, curam gero cutis

Offline

Board footer

Powered by FluxBB