Am 20.02.2011 15:04, schrieb Philip Webb:
> I fetch my mail using a user cron job, as recommended for security.
> I also start my Internet connection by hand after logging in:
> this is to avoid the jam which arises if it is included in the runlevel
> but for some reason the physical Net connection isn't functioning,
> when Dhcpcd sits there & can't be killed via Control-C.
> Usually, this works very well, but occasionally the cron job runs
> before the Dhcpcd command has made the necessary connection
> -- it depends on when the start-of-minute falls -- ,
> which results in a file  ~/dead.letter , which has to be deleted
> (the sequence of commands is clear from the Syslog file).
> 
> Is there a way to fix this ? -- I could perhaps write a 2-line script
> which would run 'dhcpcd eth0 ; /etc/init.d/vixie-cron',
> while removing Vixie-cron from the Default runlevel.
> 
> Does anyone have useful suggestions ?
> 

When dhcpcd runs, there should be the following files:
/var/run/dhcpcd.pid
/var/run/dhcpcd-eth0.pid

Just change your cron job to look like
test -e /var/run/dhcpcd.pid && fetchmail

You can also do something like parsing the output of `/sbin/ifconfig
eth0` with grep -q to see whether it has an ip address so that your cron
job also works when you configure your address statically.
/sbin/ifconfig eth0 | grep -q '\<inet' && fetchmail ...
should do the trick.

Or even more general:
gawk 'BEGIN{found=1} {if(found == 1 && $2 ~ /^0+$/ && $7 ~ /^0+$/)
found=0} END{exit found}' < /proc/net/route && fetchmail

This looks at the routing table and returns 0 when there is a default
route (destination and mask 00000000) no matter over which interface. No
clue whether this works with IPv6.

Hope this helps,
Florian Philipp

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to