public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] irritating cron habit
@ 2011-02-20 14:04 Philip Webb
  2011-02-20 15:27 ` Florian Philipp
  0 siblings, 1 reply; 6+ messages in thread
From: Philip Webb @ 2011-02-20 14:04 UTC (permalink / raw
  To: Gentoo User

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 ?

-- 
========================,,============================================
SUPPORT     ___________//___,   Philip Webb
ELECTRIC   /] [] [] [] [] []|   Cities Centre, University of Toronto
TRANSIT    `-O----------O---'   purslowatchassdotutorontodotca




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-user] irritating cron habit
  2011-02-20 14:04 [gentoo-user] irritating cron habit Philip Webb
@ 2011-02-20 15:27 ` Florian Philipp
  2011-02-20 18:18   ` Philip Webb
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Philipp @ 2011-02-20 15:27 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 1788 bytes --]

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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-user] irritating cron habit
  2011-02-20 15:27 ` Florian Philipp
@ 2011-02-20 18:18   ` Philip Webb
  2011-02-21  5:39     ` [gentoo-user] irritating cron habit : solved Philip Webb
  0 siblings, 1 reply; 6+ messages in thread
From: Philip Webb @ 2011-02-20 18:18 UTC (permalink / raw
  To: gentoo-user

110220 Florian Philipp wrote:
> Am 20.02.2011 15:04, schrieb Philip Webb:
>> I fetch my mail using a user cron job, as recommended for security.
>> Usually, this works very well, but occasionally the cron job runs
>> before the Dhcpcd command has made the necessary connection
>> which results in a file  ~/dead.letter , which has to be deleted
>> 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.
> When dhcpcd runs, there should be the following files:
>   /var/run/dhcpcd.pid       <<-- not this one
>   /var/run/dhcpcd-eth0.pid  <<-- yes
> Just change your cron job to look like
> 'test -e /var/run/dhcpcd.pid && fetchmail'

That's by far the simplest & it still fetches the mail,
so we'll see if it also avoids the occasional internal spam msgs.
Thanks for all the suggestions, which I will add to my Linux notes.

-- 
========================,,============================================
SUPPORT     ___________//___,   Philip Webb
ELECTRIC   /] [] [] [] [] []|   Cities Centre, University of Toronto
TRANSIT    `-O----------O---'   purslowatchassdotutorontodotca




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-user] irritating cron habit : solved
  2011-02-20 18:18   ` Philip Webb
@ 2011-02-21  5:39     ` Philip Webb
  2011-02-21 10:23       ` YoYo Siska
  0 siblings, 1 reply; 6+ messages in thread
From: Philip Webb @ 2011-02-21  5:39 UTC (permalink / raw
  To: gentoo-user

110220 Philip Webb wrote:
> 110220 Florian Philipp wrote:
>> Just change your cron job to look like
>> 'test -e /var/run/dhcpcd.pid && fetchmail'
> That's by far the simplest & it still fetches the mail,
> so we'll see if it also avoids the occasional internal spam msgs.

Indeed it does: I tried delaying starting the I/net connection
& there is no 'dead.letter' file.  Thanks again.

PS the file is  /var/run/dhcpcd-eth0.pid , not as above.

-- 
========================,,============================================
SUPPORT     ___________//___,   Philip Webb
ELECTRIC   /] [] [] [] [] []|   Cities Centre, University of Toronto
TRANSIT    `-O----------O---'   purslowatchassdotutorontodotca




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-user] irritating cron habit : solved
  2011-02-21  5:39     ` [gentoo-user] irritating cron habit : solved Philip Webb
@ 2011-02-21 10:23       ` YoYo Siska
  2011-02-21 11:32         ` Adam Carter
  0 siblings, 1 reply; 6+ messages in thread
From: YoYo Siska @ 2011-02-21 10:23 UTC (permalink / raw
  To: gentoo-user

On Mon, Feb 21, 2011 at 12:39:43AM -0500, Philip Webb wrote:
> 110220 Philip Webb wrote:
> > 110220 Florian Philipp wrote:
> >> Just change your cron job to look like
> >> 'test -e /var/run/dhcpcd.pid && fetchmail'
> > That's by far the simplest & it still fetches the mail,
> > so we'll see if it also avoids the occasional internal spam msgs.
> 
> Indeed it does: I tried delaying starting the I/net connection
> & there is no 'dead.letter' file.  Thanks again.
> 
> PS the file is  /var/run/dhcpcd-eth0.pid , not as above.

btw, if I need to check if the network is up in a script, I usually do

ping -q -c1 -w4 some.remote.host >/dev/null 2>&1 && command-to-run-if-remote-host-reachable

It the advantage that it checks directly connection to the host
you wish to connect to, so it also won't run the command if your network
is up, but the remote host is inaccessible...

If your server doesn't respond to pings, just use some other server
(eg google's public dns 8.8.8.8)

The -w4 paramater controls  how long to wait for reply if the network is
up, but the reply is not comming (ie a network problem, if your network
connect is down, ping will return immediately with a "network
unreachable" or "unknown host" error)

yoyo



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-user] irritating cron habit : solved
  2011-02-21 10:23       ` YoYo Siska
@ 2011-02-21 11:32         ` Adam Carter
  0 siblings, 0 replies; 6+ messages in thread
From: Adam Carter @ 2011-02-21 11:32 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 708 bytes --]

>
> btw, if I need to check if the network is up in a script, I usually do
>
> ping -q -c1 -w4 some.remote.host >/dev/null 2>&1 &&
> command-to-run-if-remote-host-reachable
>
> It the advantage that it checks directly connection to the host
> you wish to connect to, so it also won't run the command if your network
> is up, but the remote host is inaccessible...
>
> If your server doesn't respond to pings, just use some other server
> (eg google's public dns 8.8.8.8)
>


Or you could use hping, which has the advantage that it tests the actual
service you want to use, rather than just the host it sits on;

sphinx adam # hping2 -c 1 -S -p 80 www.google.com >/dev/null 2>&1 && echo
"it worked"
it worked

[-- Attachment #2: Type: text/html, Size: 1112 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-02-21 11:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-20 14:04 [gentoo-user] irritating cron habit Philip Webb
2011-02-20 15:27 ` Florian Philipp
2011-02-20 18:18   ` Philip Webb
2011-02-21  5:39     ` [gentoo-user] irritating cron habit : solved Philip Webb
2011-02-21 10:23       ` YoYo Siska
2011-02-21 11:32         ` Adam Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox