I'm having a problem with the pre-connection command under fetchmail 6.2.5 (and
I observered the same problem under 6.2.2).
I've successfully used the preconnect command to start an ssh tunnel for many
years, but now I need to do something different. I've got a dial-on-demand
router, and I want to check if the WAN connection is up before fetching new
mail. I cannot use the fetchmail interface command, since the interface between
my server and the router is always up.
I've got a script that connects to the router and indicates the status of the
WAN connection. It returns the text "online" or "offline" and sets its exit
value to either "0" or "1". The script consistently takes at least 3.5 seconds
to execute (a human-noticible interval).
I have created a shell script that does the following:
netopia status 1> /dev/null && exec ssh -f -L 9110:pop.myisp.com:110
shell.myisp.com sleep 45 < /dev/null > /dev/null
I expect the netopia command to return 1, causing the fetchmail preconnect
command to fail if the WAN connection is down. If the WAN link is up, the ssh
tunnel should be set up, and then control should pass back from the
preconnection script to the fetchmail process and mail should be retrieved.
When I use that shell script as the preconnect command, it consistently fails
with the error message:
pre-connection command failed with status 256
regardless of the WAN status.
However, if I manually run the script before and after a failed fetchmail poll,
I can see (via sh -x) that both the check of the WAN status and the ssh tunnel
setup work correctly, and that the script exits with a return code of 0 if the
WAN link is up.
Furthermore, the logs generated by fetchmail show the pre-connection command
failing within one second of the fetchmail process being awakened (the "poll
started" and "command failed" messages have the same timestamp). It appears
as if the check of the WAN status is not being run at all. I've tried
specifying the preconnect command within my .fetchmailrc as both:
poll myisp via 127.0.0.1
with proto POP3 and port 9110 and options uidl
user 'bergman' there is bergman here options no rewrite stripcr
preconnect "/bin/sh /usr/local/bin/ssh-if-wan";
and as
poll myisp via 127.0.0.1
with proto POP3 and port 9110 and options uidl
user 'bergman' there is bergman here options no rewrite stripcr
preconnect "/usr/local/bin/ssh-if-wan"
The script works fine from the command-line in either invocation.
If my shell script has just the ssh tunnel portion, it works as expected, but
this initiates a dial-out for each fetchmail poll.
I can supply the shell scripts, but they are pretty specific to my environment.
Any suggestions?
Environment:
Linux (RH 7.3, kernel 2.4.21)
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-113)
------
Mark Bergman Biker, IATSE #1 Stagehand, Rock Climber, Unix mechanic
'94 Yamaha GTS1000A^2
bergman(_at_)panix(_dot_)com
http://pgpkeys.mit.edu:11371/pks/lookup?op=get&search=bergman(_at_)panix(_dot_)com
I want a newsgroup with a infinite S/N ratio! Now taking CFV on:
rec.motorcycles.stagehands.pet-bird-owners.pinballers.unix-supporters
15+ So Far--Want to join? Check out: http://www.panix.com/~bergman