1 |
Am 20.02.2011 15:04, schrieb Philip Webb: |
2 |
> I fetch my mail using a user cron job, as recommended for security. |
3 |
> I also start my Internet connection by hand after logging in: |
4 |
> this is to avoid the jam which arises if it is included in the runlevel |
5 |
> but for some reason the physical Net connection isn't functioning, |
6 |
> when Dhcpcd sits there & can't be killed via Control-C. |
7 |
> Usually, this works very well, but occasionally the cron job runs |
8 |
> before the Dhcpcd command has made the necessary connection |
9 |
> -- it depends on when the start-of-minute falls -- , |
10 |
> which results in a file ~/dead.letter , which has to be deleted |
11 |
> (the sequence of commands is clear from the Syslog file). |
12 |
> |
13 |
> Is there a way to fix this ? -- I could perhaps write a 2-line script |
14 |
> which would run 'dhcpcd eth0 ; /etc/init.d/vixie-cron', |
15 |
> while removing Vixie-cron from the Default runlevel. |
16 |
> |
17 |
> Does anyone have useful suggestions ? |
18 |
> |
19 |
|
20 |
When dhcpcd runs, there should be the following files: |
21 |
/var/run/dhcpcd.pid |
22 |
/var/run/dhcpcd-eth0.pid |
23 |
|
24 |
Just change your cron job to look like |
25 |
test -e /var/run/dhcpcd.pid && fetchmail |
26 |
|
27 |
You can also do something like parsing the output of `/sbin/ifconfig |
28 |
eth0` with grep -q to see whether it has an ip address so that your cron |
29 |
job also works when you configure your address statically. |
30 |
/sbin/ifconfig eth0 | grep -q '\<inet' && fetchmail ... |
31 |
should do the trick. |
32 |
|
33 |
Or even more general: |
34 |
gawk 'BEGIN{found=1} {if(found == 1 && $2 ~ /^0+$/ && $7 ~ /^0+$/) |
35 |
found=0} END{exit found}' < /proc/net/route && fetchmail |
36 |
|
37 |
This looks at the routing table and returns 0 when there is a default |
38 |
route (destination and mask 00000000) no matter over which interface. No |
39 |
clue whether this works with IPv6. |
40 |
|
41 |
Hope this helps, |
42 |
Florian Philipp |